@@ -529,7 +529,9 @@ EXPORT Profile(inFile,
529529
530530 // Determine if a UTF-8 string really contains UTF-8 characters
531531 #UNIQUENAME (IsUTF8);
532- LOCAL BOOLEAN %IsUTF8%(UTF8 str) := EMBED( C++)
532+ LOCAL BOOLEAN %IsUTF8%(DATA str) := EMBED( C++)
533+ #option pure;
534+
533535 if (lenStr == 0)
534536 return false;
535537
@@ -543,37 +545,37 @@ EXPORT Profile(inFile,
543545 // ASCII; continue scan
544546 bytes += 1;
545547 }
546- else if ((0xC2 <= bytes[0] && bytes[0] <= 0xDF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF))
548+ else if ((0xC2 <= bytes[0] && bytes[0] <= 0xDF) && (bytes+1 < endPtr) && ( 0x80 <= bytes[1] && bytes[1] <= 0xBF))
547549 {
548550 // Valid non-overlong 2-byte
549551 return true;
550552 }
551- else if (bytes[0] == 0xE0 && (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))
553+ else if (bytes[0] == 0xE0 && (bytes+2 < endPtr) && ( 0xA0 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))
552554 {
553555 // Valid excluding overlongs
554556 return true;
555557 }
556- else if (((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || bytes[0] == 0xEE || bytes[0] == 0xEF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))
558+ else if (((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || bytes[0] == 0xEE || bytes[0] == 0xEF) && (bytes+2 < endPtr) && ( 0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))
557559 {
558560 // Valid straight 3-byte
559561 return true;
560562 }
561- else if (bytes[0] == 0xED && (0x80 <= bytes[1] && bytes[1] <= 0x9F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))
563+ else if (bytes[0] == 0xED && (bytes+2 < endPtr) && ( 0x80 <= bytes[1] && bytes[1] <= 0x9F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))
562564 {
563565 // Valid excluding surrogates
564566 return true;
565567 }
566- else if (bytes[0] == 0xF0 && (0x90 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))
568+ else if (bytes[0] == 0xF0 && (bytes+3 < endPtr) && ( 0x90 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))
567569 {
568570 // Valid planes 1-3
569571 return true;
570572 }
571- else if ((0xF1 <= bytes[0] && bytes[0] <= 0xF3) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))
573+ else if ((0xF1 <= bytes[0] && bytes[0] <= 0xF3) && (bytes+3 < endPtr) && ( 0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))
572574 {
573575 // Valid planes 4-15
574576 return true;
575577 }
576- else if (bytes[0] == 0xF4 && (0x80 <= bytes[1] && bytes[1] <= 0x8F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))
578+ else if (bytes[0] == 0xF4 && (bytes+3 < endPtr) && ( 0x80 <= bytes[1] && bytes[1] <= 0x8F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))
577579 {
578580 // Valid plane 16
579581 return true;
@@ -613,9 +615,9 @@ EXPORT Profile(inFile,
613615 // Pattern mapping a UNICODE datatype; using regex due to the complexity
614616 // of the character set
615617 #UNIQUENAME (_MapUpperCharUni);
616- LOCAL %_MapUpperCharUni%(UNICODE s) := REGEXREPLACE (u '\\ p{Uppercase_Letter }' , s, u 'A' );
618+ LOCAL %_MapUpperCharUni%(UNICODE s) := REGEXREPLACE (u '\\ p{Lu }' , s, u 'A' );
617619 #UNIQUENAME (_MapLowerCharUni);
618- LOCAL %_MapLowerCharUni%(UNICODE s) := REGEXREPLACE (u '[[\\ p{Lowercase_Letter }][\\ p{Titlecase_Letter }][\\ p{Modifier_Letter }][\\ p{Other_Letter }]]' , s, u 'a' );
620+ LOCAL %_MapLowerCharUni%(UNICODE s) := REGEXREPLACE (u '[[\\ p{Ll }][\\ p{Lt }][\\ p{Lm }][\\ p{Lo }]]' , s, u 'a' );
619621 #UNIQUENAME (_MapDigitUni);
620622 LOCAL %_MapDigitUni%(UNICODE s) := REGEXREPLACE (u '[1-9]' , s, u '9' ); // Leave '0' as-is and replace with '9' later
621623 #UNIQUENAME (_MapAllUni);
@@ -824,7 +826,7 @@ EXPORT Profile(inFile,
824826 #IF (%_IsSetType%(%'@type' %))
825827 FALSE
826828 #ELSEIF (REGEXFIND ('(unicode)|(utf)' , %'@type' %))
827- %IsUTF8%((UTF8 )_inFile.#EXPAND (%'namePrefix' % + %'@name' %))
829+ %IsUTF8%((DATA )_inFile.#EXPAND (%'namePrefix' % + %'@name' %))
828830 #ELSE
829831 FALSE
830832 #END
0 commit comments