Remove useless iteration when debug mode
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / character-run.h
index 221ecbd..757beb0 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_TOOLKIT_TEXT_CHARACTER_RUN_H__
-#define __DALI_TOOLKIT_TEXT_CHARACTER_RUN_H__
+#ifndef DALI_TOOLKIT_TEXT_CHARACTER_RUN_H
+#define DALI_TOOLKIT_TEXT_CHARACTER_RUN_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Text
 {
-
 /**
  * @brief A run of consecutive characters.
  */
 struct CharacterRun
 {
+  CharacterRun()
+  : characterIndex{0u},
+    numberOfCharacters{0u}
+  {
+  }
+
+  CharacterRun(CharacterIndex characterIndex, Length numberOfCharacters)
+  : characterIndex{characterIndex},
+    numberOfCharacters{numberOfCharacters}
+  {
+  }
+
   CharacterIndex characterIndex;     ///< Index to the first character.
   Length         numberOfCharacters; ///< Number of characters in the run.
+
+  //Methods
+
+  /**
+  * @brief Calculate the end index in run.
+  * @return the end character index in run.
+  */
+  CharacterIndex GetEndCharacterIndex() const
+  {
+    DALI_ASSERT_DEBUG(!((0u == numberOfCharacters) && (characterIndex > 0u)) &&
+                      "Toolkit::Text::CharacterRun. NumberOfCharacters should be greater than zero");
+
+    // Note: Length is uint32. Extra validation to avoid a potential defects.
+    return (numberOfCharacters == 0u ? 0u : (characterIndex + numberOfCharacters - 1u));
+  }
 };
 
 } // namespace Text
@@ -45,4 +69,4 @@ struct CharacterRun
 
 } // namespace Dali
 
-#endif // __DALI_TOOLKIT_TEXT_CHARACTER_RUN_H__
+#endif // DALI_TOOLKIT_TEXT_CHARACTER_RUN_H