For compatibility with existing translations we use %s to print Unicode strings in format strings and convert them to %ls here. %s could work without such conversion in Windows, but not in Unix wprintf.
| 435 | // strings in format strings and convert them to %ls here. %s could work |
| 436 | // without such conversion in Windows, but not in Unix wprintf. |
| 437 | void PrintfPrepareFmt(const wchar *Org,wchar *Cvt,size_t MaxSize) |
| 438 | { |
| 439 | uint Src=0,Dest=0; |
| 440 | while (Org[Src]!=0 && Dest<MaxSize-1) |
| 441 | { |
| 442 | if (Org[Src]=='%' && (Src==0 || Org[Src-1]!='%')) |
| 443 | { |
| 444 | uint SPos=Src+1; |
| 445 | // Skipping a possible width specifier like %-50s. |
| 446 | while (IsDigit(Org[SPos]) || Org[SPos]=='-') |
| 447 | SPos++; |
| 448 | if (Org[SPos]=='s' && Dest<MaxSize-(SPos-Src+1)) |
| 449 | { |
| 450 | while (Src<SPos) |
| 451 | Cvt[Dest++]=Org[Src++]; |
| 452 | Cvt[Dest++]='l'; |
| 453 | } |
| 454 | } |
| 455 | #ifdef _WIN_ALL |
| 456 | // Convert \n to \r\n in Windows. Important when writing to log, |
| 457 | // so other tools like Notebook can view resulting log properly. |
| 458 | if (Org[Src]=='\n' && (Src==0 || Org[Src-1]!='\r')) |
| 459 | Cvt[Dest++]='\r'; |
| 460 | #endif |
| 461 | |
| 462 | Cvt[Dest++]=Org[Src++]; |
| 463 | } |
| 464 | Cvt[Dest]=0; |
| 465 | } |
| 466 | #endif |
no test coverage detected