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 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
682
+ 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 ,
683
+ 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
684
+ };
685
+
686
+ int git__utf8_charlen (const uint8_t * str , int str_len )
687
+ {
688
+ int length , i ;
689
+
690
+ length = utf8proc_utf8class [str [0 ]];
691
+ if (!length )
692
+ return -1 ;
693
+
694
+ if (str_len >= 0 && length > str_len )
695
+ return - str_len ;
696
+
697
+ for (i = 1 ; i < length ; i ++ ) {
698
+ if ((str [i ] & 0xC0 ) != 0x80 )
699
+ return - i ;
700
+ }
701
+
702
+ return length ;
703
+ }
704
+
705
+ int git__utf8_iterate (const uint8_t * str , int str_len , int32_t * dst )
706
+ {
707
+ int length ;
708
+ int32_t uc = -1 ;
709
+
710
+ * dst = -1 ;
711
+ length = git__utf8_charlen (str , str_len );
712
+ if (length < 0 )
713
+ return -1 ;
714
+
715
+ switch (length ) {
716
+ case 1 :
717
+ uc = str [0 ];
718
+ break ;
719
+ case 2 :
720
+ uc = ((str [0 ] & 0x1F ) << 6 ) + (str [1 ] & 0x3F );
721
+ if (uc < 0x80 ) uc = -1 ;
722
+ break ;
723
+ case 3 :
724
+ uc = ((str [0 ] & 0x0F ) << 12 ) + ((str [1 ] & 0x3F ) << 6 )
725
+ + (str [2 ] & 0x3F );
726
+ if (uc < 0x800 || (uc >= 0xD800 && uc < 0xE000 ) ||
727
+ (uc >= 0xFDD0 && uc < 0xFDF0 )) uc = -1 ;
728
+ break ;
729
+ case 4 :
730
+ uc = ((str [0 ] & 0x07 ) << 18 ) + ((str [1 ] & 0x3F ) << 12 )
731
+ + ((str [2 ] & 0x3F ) << 6 ) + (str [3 ] & 0x3F );
732
+ if (uc < 0x10000 || uc >= 0x110000 ) uc = -1 ;
733
+ break ;
734
+ }
735
+
736
+ if (uc < 0 || ((uc & 0xFFFF ) >= 0xFFFE ))
737
+ return -1 ;
738
+
739
+ * dst = uc ;
740
+ return length ;
741
+ }
0 commit comments