I want to write a function in Delphi to check if two strings contain the same list of format specifiers. One string is in English, and another is translated into another language.
For example,
string1 = 'The number is %d.'
string2 = '这个数字是%d.'
Sometimes, the translator will make a mistake and modify the format specifier, like below:
string2 = '这个数字是% d.'
So I want to write a function to perform the check automatically. The function needs to collect all the format specifiers in the string. Since there are many cases to consider, I want to modify the existing source codes instead of writing from the beginning.
I have already done so by modifying Delphi's WideFormatBuf function to support Delphi strings.
Now to support C++ strings, I am looking for existing Delphi codes to parse printf format specifier so that I can also modify based on them(my code is Delphi)
wsprintf in this post does not work for my case, as it does not contain the actual source codes in parsing the format specifiers.
%(?'flags'[-+ #0])?(?'width'(?:\d+|\*))?(?'precision'\.(?:\d+|\*))?(?'length'(?:h|hh|l|ll|j|z|t|L))?(?'specifier'[diuoxXfFeEgGaAcspn%])
printf
implementation, but you can check out GLibC implementation in C