From 43c8661e5e26f077ffd54966a206cef13b17c898 Mon Sep 17 00:00:00 2001
From: vro <vro@opencascade.com>
Date: Mon, 18 Mar 2019 10:16:40 +0300
Subject: [PATCH] 0030536: Foundation Classes -
 TCollection_ExtendedString::StartsWith() and EndsWith() have a mistake

Draw-commands StartsWith and EndsWith are renamed to QAStartsWith and QAEndsWith.
The test script bug30536 was corrected.
---
 src/QABugs/QABugs_20.cxx                      | 46 +++++++++++++++++++
 .../TCollection_ExtendedString.cxx            |  4 +-
 tests/bugs/fclasses/bug30536                  | 25 ++++++++++
 3 files changed, 73 insertions(+), 2 deletions(-)
 create mode 100644 tests/bugs/fclasses/bug30536

diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx
index f39126507a..14e04bb923 100644
--- a/src/QABugs/QABugs_20.cxx
+++ b/src/QABugs/QABugs_20.cxx
@@ -3060,6 +3060,44 @@ static Standard_Integer OCC30391(Draw_Interpretor& theDI,
   return 0;
 }
 
+//=======================================================================
+//function : QAStartsWith string startstring
+//=======================================================================
+static Standard_Integer QAStartsWith(Draw_Interpretor& di, Standard_Integer n, const char** a)
+{
+  if (n == 3)
+  {
+    TCollection_ExtendedString str = a[1];
+    TCollection_ExtendedString startstr = a[2];
+    if (str.StartsWith(startstr))
+      di << "Yes";
+    else
+      di << "No";
+    return 0;
+  }
+  std::cerr << "Syntax error\n";
+  return 1;
+}
+
+//=======================================================================
+//function : QAEndsWith string endstring
+//=======================================================================
+static Standard_Integer QAEndsWith(Draw_Interpretor& di, Standard_Integer n, const char** a)
+{
+  if (n == 3)
+  {
+    TCollection_ExtendedString str = a[1];
+    TCollection_ExtendedString endstr = a[2];
+    if (str.EndsWith(endstr))
+      di << "Yes";
+    else
+      di << "No";
+    return 0;
+  }
+  std::cerr << "Syntax error\n";
+  return 1;
+}
+
 void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   const char *group = "QABugs";
 
@@ -3101,5 +3139,13 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   theCommands.Add("OCC29311", "OCC29311 shape counter nbiter: check performance of OBB calculation", __FILE__, OCC29311, group);
   theCommands.Add("OCC30391", "OCC30391 result face LenBeforeUfirst LenAfterUlast LenBeforeVfirst LenAfterVlast", __FILE__, OCC30391, group);
 
+  theCommands.Add("QAStartsWith",
+                  "QAStartsWith string startstring",
+                  __FILE__, QAStartsWith, group);
+
+  theCommands.Add("QAEndsWith",
+                  "QAEndsWith string endstring",
+                  __FILE__, QAEndsWith, group);
+
   return;
 }
diff --git a/src/TCollection/TCollection_ExtendedString.cxx b/src/TCollection/TCollection_ExtendedString.cxx
index 5e0aef7521..92eb847ed2 100644
--- a/src/TCollection/TCollection_ExtendedString.cxx
+++ b/src/TCollection/TCollection_ExtendedString.cxx
@@ -539,7 +539,7 @@ Standard_Boolean TCollection_ExtendedString::StartsWith (const TCollection_Exten
   }
 
   return mylength >= theStartString.mylength
-      && memcmp (theStartString.mystring, mystring, theStartString.mylength) == 0;
+      && memcmp (theStartString.mystring, mystring, theStartString.mylength * sizeof(Standard_ExtCharacter)) == 0;
 }
 
 // ----------------------------------------------------------------------------
@@ -553,7 +553,7 @@ Standard_Boolean TCollection_ExtendedString::EndsWith (const TCollection_Extende
   }
 
   return mylength >= theEndString.mylength
-      && memcmp (theEndString.mystring, mystring + mylength - theEndString.mylength, theEndString.mylength) == 0;
+      && memcmp (theEndString.mystring, mystring + mylength - theEndString.mylength, theEndString.mylength * sizeof(Standard_ExtCharacter)) == 0;
 }
 
 // ----------------------------------------------------------------------------
diff --git a/tests/bugs/fclasses/bug30536 b/tests/bugs/fclasses/bug30536
new file mode 100644
index 0000000000..6f20c79d10
--- /dev/null
+++ b/tests/bugs/fclasses/bug30536
@@ -0,0 +1,25 @@
+puts "============"
+puts "0030536: Foundation Classes - TCollection_ExtendedString::StartsWith() and EndsWith() have a mistake"
+puts "============"
+
+pload QAcommands
+
+set ret1 [QAStartsWith hello help]
+if { ${ret1} == "Yes" } {
+    puts "Error"
+}
+
+set ret2 [QAStartsWith hello he]
+if { ${ret2} == "No" } {
+    puts "Error"
+}
+
+set ret3 [QAEndsWith hello ll]
+if { ${ret3} == "Yes" } {
+    puts "Error"
+}
+
+set ret4 [QAEndsWith hello lo]
+if { ${ret4} == "No" } {
+    puts "Error"
+}