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

Function AnyLanguage_ReadCharFromString

code/rd-common/tr_font.cpp:716–922  ·  view source on GitHub ↗

takes char *, returns integer char at that point, and advances char * on by enough bytes to move past the letter (either western 1 byte or Asian multi-byte)... looks messy, but the actual execution route is quite short, so it's fast... Note that I have to have this 3-param form instead of advancing a passed-in "const char **psText" because of VM-crap where you can only change ptr-contents, not p

Source from the content-addressed store, hash-verified

714// Note that I have to have this 3-param form instead of advancing a passed-in "const char **psText" because of VM-crap where you can only change ptr-contents, not ptrs themselves. Bleurgh. Ditto the qtrue:qfalse crap instead of just returning stuff straight through.
715//
716unsigned int AnyLanguage_ReadCharFromString( char *psText, int *piAdvanceCount, qboolean *pbIsTrailingPunctuation /* = NULL */)
717{
718#ifdef JK2_MODE
719 // JK2 does this func a little differently --eez
720 const byte *psString = (const byte *) psText; // avoid sign-promote bug
721 unsigned int uiLetter;
722
723 if ( Language_IsKorean() )
724 {
725 if ( Korean_ValidKSC5601Hangul( psString[0], psString[1] ))
726 {
727 uiLetter = (psString[0] * 256) + psString[1];
728 psText += 2;
729 *piAdvanceCount = 2;
730
731 // not going to bother testing for korean punctuation here, since korean already
732 // uses spaces, and I don't have the punctuation glyphs defined, only the basic 2350 hanguls
733 //
734 if ( pbIsTrailingPunctuation)
735 {
736 *pbIsTrailingPunctuation = qfalse;
737 }
738
739 return uiLetter;
740 }
741 }
742 else
743 if ( Language_IsTaiwanese() )
744 {
745 if ( Taiwanese_ValidBig5Code( (psString[0] * 256) + psString[1] ))
746 {
747 uiLetter = (psString[0] * 256) + psString[1];
748 psText += 2;
749 *piAdvanceCount = 2;
750
751 // need to ask if this is a trailing (ie like a comma or full-stop) punctuation?...
752 //
753 if ( pbIsTrailingPunctuation)
754 {
755 *pbIsTrailingPunctuation = Taiwanese_IsTrailingPunctuation( uiLetter );
756 }
757
758 return uiLetter;
759 }
760 }
761 else
762 if ( Language_IsJapanese() )
763 {
764 if ( Japanese_ValidShiftJISCode( psString[0], psString[1] ))
765 {
766 uiLetter = (psString[0] * 256) + psString[1];
767 psText += 2;
768 *piAdvanceCount = 2;
769
770 // need to ask if this is a trailing (ie like a comma or full-stop) punctuation?...
771 //
772 if ( pbIsTrailingPunctuation)
773 {

Callers 4

RE_Font_StrLenPixelsFunction · 0.70
RE_Font_StrLenCharsFunction · 0.70
RE_Font_DrawStringFunction · 0.70

Calls 13

Taiwanese_ValidBig5CodeFunction · 0.70
GetLanguageEnumFunction · 0.70
Chinese_ValidGBCodeFunction · 0.70
Thai_ValidTISCodeFunction · 0.70
Language_IsKoreanFunction · 0.50
Language_IsTaiwaneseFunction · 0.50

Tested by

no test coverage detected