MCPcopy Create free account
hub / github.com/JACoders/OpenJK / CopeWithDumbStringData

Function CopeWithDumbStringData

code/qcommon/stringed_ingame.cpp:500–591  ·  view source on GitHub ↗

this copes with both foreigners using hi-char values (eg the french using 0x92 instead of 0x27 for a "'" char), as well as the fact that our buggy fontgen program writes out zeroed glyph info for some fonts anyway (though not all, just as a gotcha). New bit, instead of static buffer (since XBox guys are desperately short of mem) I return a malloc'd buffer now, so remember to free it!

Source from the content-addressed store, hash-verified

498// so remember to free it!
499//
500static char *CopeWithDumbStringData( const char *psSentence, const char *psThisLanguage )
501{
502 const int iBufferSize = strlen(psSentence)*3; // *3 to allow for expansion of anything even stupid string consisting entirely of elipsis chars
503 char *psNewString = (char *) Z_Malloc(iBufferSize, TAG_TEMP_WORKSPACE, qfalse);
504 Q_strncpyz(psNewString, psSentence, iBufferSize);
505
506 // this is annoying, I have to just guess at which languages to do it for (ie NOT ASIAN/MBCS!!!) since the
507 // string system was deliberately (and correctly) designed to not know or care whether it was doing SBCS
508 // or MBCS languages, because it was never envisioned that I'd have to clean up other people's mess.
509 //
510 // Ok, bollocks to it, this will have to do. Any other languages that come later and have bugs in their text can
511 // get fixed by them typing it in properly in the first place...
512 //
513 if (!Q_stricmp(psThisLanguage,"ENGLISH") ||
514 !Q_stricmp(psThisLanguage,"FRENCH") ||
515 !Q_stricmp(psThisLanguage,"GERMAN") ||
516 !Q_stricmp(psThisLanguage,"ITALIAN") ||
517 !Q_stricmp(psThisLanguage,"SPANISH") ||
518 !Q_stricmp(psThisLanguage,"POLISH") ||
519 !Q_stricmp(psThisLanguage,"RUSSIAN")
520 )
521 {
522 char *p;
523
524 // strXLS_Speech.Replace(va("%c",0x92),va("%c",0x27)); // "'"
525 while ((p=strchr(psNewString,0x92))!=NULL) // "rich" (and illegal) apostrophe
526 {
527 *p = 0x27;
528 }
529
530 // strXLS_Speech.Replace(va("%c",0x93),"\""); // smart quotes -> '"'
531 while ((p=strchr(psNewString,0x93))!=NULL)
532 {
533 *p = '"';
534 }
535
536 // strXLS_Speech.Replace(va("%c",0x94),"\""); // smart quotes -> '"'
537 while ((p=strchr(psNewString,0x94))!=NULL)
538 {
539 *p = '"';
540 }
541
542 // strXLS_Speech.Replace(va("%c",0x0B),"."); // full stop
543 while ((p=strchr(psNewString,0x0B))!=NULL)
544 {
545 *p = '.';
546 }
547
548 // strXLS_Speech.Replace(va("%c",0x85),"..."); // "..."-char -> 3-char "..."
549 while ((p=strchr(psNewString,0x85))!=NULL) // "rich" (and illegal) apostrophe
550 {
551 memmove(p+2,p,strlen(p));
552 *p++ = '.';
553 *p++ = '.';
554 *p = '.';
555 }
556
557 // strXLS_Speech.Replace(va("%c",0x91),va("%c",0x27)); // "'"

Callers 1

ParseLineMethod · 0.70

Calls 3

Q_strncpyzFunction · 0.85
Q_stricmpFunction · 0.85
Z_MallocFunction · 0.70

Tested by

no test coverage detected