0

I'm using libconfig. I've a .cfg file. In this file, I have one only category: Services. Inside this category, I have many objects. Each object name has this format:

objectname + underscore + 4numbers

For example:

alfa_1111

So, let's consider:

Services = 
{

   alfa_1111 = {
     
    key = "value"

  };

   beta_2222 = {
     
    key = "value"

  };

   gamma_3333 = {
     
    key = "value"

  };

}

The 4 numbers are a unique identifier. There is one only 1111, one only 2222 and so on. My scope is to retrivie the key value for a specific object. The problem is, that the only parameter I know, are the 4 numbers.

To be more clear: I receive for example 2222. I know that in the file there is one only 2222, so I look into beta_2222 and retrieve the key value.

However, I am not aware of the name before the underscore. I simply receive 2222. So, inside the .cfg there could be any name before _2222 (x_2222? y_2222? z_2222?)

So, in the config lookup I would need something like that:

config_setting_t *setting;
config_t cfg;
setting = config_lookup(&cfg, "Services.*_2222);

(with * I mean "any character you find until _2222")

Is there a way to say:

search for the object that contains _2222, it doesn't matter of the previous characters...

markalex
  • 8,623
  • 2
  • 7
  • 32
LearningC
  • 88
  • 1
  • 8
  • The C++ classes seems to have functionality to iterate over settings, but there doesn't seem to be any equivalent functions in the C API. Otherwise you could iterate over all settings inside `Service` and just look for a setting ending in the string `"2222"`. – Some programmer dude Nov 25 '22 at 09:36
  • how could I do this? Do you mean to look for every single object and parse it to verify if it contains _2222? – LearningC Nov 25 '22 at 09:41
  • If it was possible to get a list of every single "object" then yes that's what I'm proposing. Unfortunately using the public C API it doesn't seem possible to get such a list. – Some programmer dude Nov 25 '22 at 09:53

0 Answers0