0

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.

7
  • 3
    %(?'flags'[-+ #0])?(?'width'(?:\d+|\*))?(?'precision'\.(?:\d+|\*))?(?'length'(?:h|hh|l|ll|j|z|t|L))?(?'specifier'[diuoxXfFeEgGaAcspn%])
    – Peter Wolf
    Oct 3 at 7:29
  • I don't know any Delphi printf implementation, but you can check out GLibC implementation in C
    – Peter Wolf
    Oct 3 at 7:35
  • @PeterWolf, ´printf´ as well as ´sprintf´ are part of System.Win.Crtl.pas, but they are declared external, linked to msvcrt.dll. Nevertheless they can be used from Delphi on Windows platforms.
    – Uwe Raabe
    Oct 3 at 9:00
  • @UweRaabe That's correct, but OP looks for Delphi implementation.
    – Peter Wolf
    Oct 3 at 9:36
  • 2
    I wrote it myself ;)
    – Peter Wolf
    Oct 3 at 10:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.