fix incorrect index range in emoji-helper 20/276720/2
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 23 Jun 2022 09:56:41 +0000 (18:56 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Thu, 23 Jun 2022 11:02:12 +0000 (20:02 +0900)
Length lastCharacter = startIndex + numberOfCharacters;

Previous lastCharacter's actual value is "lastCharacter + 1"
This incorrect value makes the whole code misleading.

Change-Id: Idcb2582b05b2e36d064779f85942cea6d967a755
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali-toolkit/internal/text/emoji-helper.cpp
dali-toolkit/internal/text/multi-language-support-impl.cpp

index eec4ee4..c458fd0 100644 (file)
@@ -77,7 +77,7 @@ bool IsNewKeycapSequence(const Character* const   textBuffer,
   // Default initialization does not keycap sequence
   bool isNewKeycapSequence = false;
 
   // Default initialization does not keycap sequence
   bool isNewKeycapSequence = false;
 
-  if(currentCharacterIndex < lastCharacterIndex)
+  if(currentCharacterIndex <= lastCharacterIndex)
   {
     Character currentCharacter = *(textBuffer + currentCharacterIndex);
     if(IsStartForKeycapSequence(currentCharacter))
   {
     Character currentCharacter = *(textBuffer + currentCharacterIndex);
     if(IsStartForKeycapSequence(currentCharacter))
@@ -112,7 +112,7 @@ bool IsNewVariationSelectorSequence(const Character* const         textBuffer,
   // Default initialization does not VariationSelector sequence
   bool isNewVariationSelectorSequence = false;
 
   // Default initialization does not VariationSelector sequence
   bool isNewVariationSelectorSequence = false;
 
-  if(currentCharacterIndex < lastCharacterIndex)
+  if(currentCharacterIndex <= lastCharacterIndex)
   {
     Character currentCharacter = *(textBuffer + currentCharacterIndex);
     if(TextAbstraction::IsEmojiVariationSequences(currentCharacter))
   {
     Character currentCharacter = *(textBuffer + currentCharacterIndex);
     if(TextAbstraction::IsEmojiVariationSequences(currentCharacter))
index 52f2b18..96210ca 100644 (file)
@@ -205,9 +205,9 @@ void MultilanguageSupport::SetScripts(const Vector<Character>& text,
   currentScriptRun.isRightToLeft = false;
 
   // Traverse all characters and set the scripts.
   currentScriptRun.isRightToLeft = false;
 
   // Traverse all characters and set the scripts.
-  const Length lastCharacter = startIndex + numberOfCharacters;
+  const Length lastCharacter = startIndex + numberOfCharacters - 1u;
 
 
-  for(Length index = startIndex; index < lastCharacter; ++index)
+  for(Length index = startIndex; index <= lastCharacter; ++index)
   {
     Character character = *(textBuffer + index);
 
   {
     Character character = *(textBuffer + index);
 
@@ -223,7 +223,7 @@ void MultilanguageSupport::SetScripts(const Vector<Character>& text,
     //   script of the first character of the paragraph with a defined script.
 
     // Skip those characters valid for many scripts like white spaces or '\n'.
     //   script of the first character of the paragraph with a defined script.
 
     // Skip those characters valid for many scripts like white spaces or '\n'.
-    bool endOfText = index == lastCharacter;
+    bool endOfText = index > lastCharacter;
 
     //Handle all Emoji Sequence cases
     if(IsNewSequence(textBuffer, currentScriptRun.script, index, lastCharacter, script))
 
     //Handle all Emoji Sequence cases
     if(IsNewSequence(textBuffer, currentScriptRun.script, index, lastCharacter, script))
@@ -280,7 +280,7 @@ void MultilanguageSupport::SetScripts(const Vector<Character>& text,
 
       // Get the next character.
       ++index;
 
       // Get the next character.
       ++index;
-      endOfText = index == lastCharacter;
+      endOfText = index > lastCharacter;
       if(!endOfText)
       {
         character = *(textBuffer + index);
       if(!endOfText)
       {
         character = *(textBuffer + index);
@@ -471,8 +471,8 @@ void MultilanguageSupport::ValidateFonts(const Vector<Character>&
   FontId                  previousEmojiFontId = 0u;
   TextAbstraction::Script previousScript      = TextAbstraction::UNKNOWN;
 
   FontId                  previousEmojiFontId = 0u;
   TextAbstraction::Script previousScript      = TextAbstraction::UNKNOWN;
 
-  CharacterIndex lastCharacter = startIndex + numberOfCharacters;
-  for(Length index = startIndex; index < lastCharacter; ++index)
+  CharacterIndex lastCharacter = startIndex + numberOfCharacters - 1u;
+  for(Length index = startIndex; index <= lastCharacter; ++index)
   {
     // Get the current character.
     const Character character        = *(textBuffer + index);
   {
     // Get the current character.
     const Character character        = *(textBuffer + index);