I am trying to parse a text file, but I feel that there should be a better way to do this.
A text file consists of elements that can contain both key value pairs and other elements. I believe that the file will only reach the element of the grandson (for example, the element inside the element, inside the element).
I am currently repeating the file line by line and keeping track of the depth at which I am. Then, as soon as I get to the termination character ('}'), and I'm at level 0, I know that I have captured the whole parent element.
Since I don’t think I explained it well, my file structure will look something like this.
parent_item {
key: value
key: value
child_item {
key: value
key: value
}
child_item {
key: value
key: value
key: value
grandchild_item {
key: value
key: value
}
}
key: value
key: value
}
parent_item {
key: value
key: value
child_item {
key: value
key: value
}
}
0 , , - , 3 ( → → ).
, ?