We have a pair of strings for example such pair Accept-Language : RU , and we search thru map, for example of http request headers. All we ned to know if there is such pair in map or not – a bool value. How to do to a soft search meaning we do not need to find exact same pair but pair like Accept-Language : ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4 is also a valid pair for us and if such exists we can think we have found that our map contains our pair. How to make a function for performing such search in C++?
We have a pair of strings for example such pair Accept-Language : RU ,
Share
First of all, if you are using a
map, you cannot have multiple entries with the same key. E.g. you can’t have bothAccept-Language : RUandAccept-Language : ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4because they have the same key `Accept-Language’. Perhaps in your case you should use a vector of pairs, or a multimap.Next, your question consists of 2 parts:
stringorpair)matches a pattern.
such a check, how to apply it to
each element in a container.
The solutions to each part:
string, or apair(depends on the type of container and stored element that you choose), and checks whether it matches your criteria. You can find the functions such as string::find_first_of to be useful for that matter. The regex libraries can be even more helpful, though they are not part of the STL.