@@ -682,3 +682,35 @@ bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const
682682
683683 return false;
684684}
685+
686+ int ffStrbufAppendUtf32CodePoint (FFstrbuf * strbuf , uint32_t codepoint )
687+ {
688+ if (codepoint <= 0x7F ) {
689+ ffStrbufAppendC (strbuf , (char )codepoint );
690+ return 1 ;
691+ } else if (codepoint <= 0x7FF ) {
692+ ffStrbufAppendNS (strbuf , 2 , (char []){
693+ (char ) (0xC0 | (codepoint >> 6 )),
694+ (char ) (0x80 | (codepoint & 0x3F ))
695+ });
696+ return 2 ;
697+ } else if (codepoint <= 0xFFFF ) {
698+ ffStrbufAppendNS (strbuf , 3 , (char []){
699+ (char ) (0xE0 | (codepoint >> 12 )),
700+ (char ) (0x80 | ((codepoint >> 6 ) & 0x3F )),
701+ (char ) (0x80 | (codepoint & 0x3F ))
702+ });
703+ return 3 ;
704+ } else if (codepoint <= 0x10FFFF ) {
705+ ffStrbufAppendNS (strbuf , 4 , (char []){
706+ (char ) (0xF0 | (codepoint >> 18 )),
707+ (char ) (0x80 | ((codepoint >> 12 ) & 0x3F )),
708+ (char ) (0x80 | ((codepoint >> 6 ) & 0x3F )),
709+ (char ) (0x80 | (codepoint & 0x3F ))
710+ });
711+ return 4 ;
712+ }
713+
714+ ffStrbufAppendS (strbuf , "�" ); // U+FFFD REPLACEMENT CHARACTER
715+ return 1 ;
716+ }
0 commit comments