]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/TianoTools/String/String.c
Add new OSS License
[mirror_edk2.git] / Tools / Source / TianoTools / String / String.c
index 10051806ad59e80e38b045a5218f69d74b7f63e8..9e02231f364f420efd99db96b3d25da43c06ec69 100644 (file)
@@ -1,11 +1,14 @@
 /** @file\r
   Unicode string primatives.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
+Copyright (c)  2004-2006 Intel Corporation. All rights reserved\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 **/\r
 \r
 #include <assert.h>\r
-#include <Base.h>\r
-#include <UefiBaseTypes.h>\r
-#include <BaseLib.h>\r
-#include <PcdLib.h>\r
-#include <CommonLib.h>\r
-#define _gPcd_FixedAtBuild_PcdMaximumUnicodeStringLength   0\r
-#define _gPcd_FixedAtBuild_PcdMaximumAsciiStringLength   0\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+#include "CommonLib.h"\r
+\r
+/**\r
+  Returns the length of a Null-terminated Unicode string.\r
+\r
+  This function returns the number of Unicode characters in the Null-terminated\r
+  Unicode string specified by String.\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  @param  String  Pointer to a Null-terminated Unicode string.\r
+\r
+  @return The length of String.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+StrLen (\r
+  IN      CONST CHAR16              *String\r
+  )\r
+{\r
+  UINTN                             Length;\r
+\r
+  ASSERT (String != NULL);\r
+\r
+  for (Length = 0; *String != L'\0'; String++, Length++) {\r
+    ;\r
+  }\r
+  return Length;\r
+}\r
+\r
+/**\r
+  Returns the length of a Null-terminated ASCII string.\r
+\r
+  This function returns the number of ASCII characters in the Null-terminated\r
+  ASCII string specified by String.\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  @param  String  Pointer to a Null-terminated ASCII string.\r
+\r
+  @return The length of String.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+AsciiStrLen (\r
+  IN      CONST CHAR8               *String\r
+  )\r
+{\r
+  UINTN                             Length;\r
+\r
+  ASSERT (String != NULL);\r
+\r
+  for (Length = 0; *String != '\0'; String++, Length++) {\r
+    ;\r
+  }\r
+  return Length;\r
+}\r
 \r
 /**\r
   Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
@@ -34,8 +92,6 @@
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated Unicode string.\r
   @param  Source      Pointer to a Null-terminated Unicode string.\r
@@ -87,8 +143,6 @@ StrCpy (
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated Unicode string.\r
   @param  Source      Pointer to a Null-terminated Unicode string.\r
@@ -130,48 +184,10 @@ StrnCpy (
     Length--;\r
   }\r
 \r
-  // ZeroMem (Destination, Length * sizeof (*Destination));\r
   memset (Destination, 0, Length * sizeof (*Destination));\r
   return ReturnValue;\r
 }\r
 \r
-/**\r
-  Returns the length of a Null-terminated Unicode string.\r
-\r
-  This function returns the number of Unicode characters in the Null-terminated\r
-  Unicode string specified by String.\r
-\r
-  If String is NULL, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
-\r
-  @param  String  Pointer to a Null-terminated Unicode string.\r
-\r
-  @return The length of String.\r
-\r
-**/\r
-UINTN\r
-EFIAPI\r
-StrLen (\r
-  IN      CONST CHAR16              *String\r
-  )\r
-{\r
-  UINTN                             Length;\r
-\r
-  ASSERT (String != NULL);\r
-\r
-  for (Length = 0; *String != L'\0'; String++, Length++) {\r
-    //\r
-    // If PcdMaximumUnicodeStringLength is not zero,\r
-    // length should not more than PcdMaximumUnicodeStringLength\r
-    //\r
-    if (FixedPcdGet32 (PcdMaximumUnicodeStringLength) != 0) {\r
-      ASSERT (Length < FixedPcdGet32 (PcdMaximumUnicodeStringLength));\r
-    }\r
-  }\r
-  return Length;\r
-}\r
-\r
 /**\r
   Returns the size of a Null-terminated Unicode string in bytes, including the\r
   Null terminator.\r
@@ -180,8 +196,6 @@ StrLen (
   string specified by String.\r
 \r
   If String is NULL, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
 \r
   @param  String  Pointer to a Null-terminated Unicode string.\r
 \r
@@ -209,10 +223,6 @@ StrSize (
 \r
   If FirstString is NULL, then ASSERT().\r
   If SecondString is NULL, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
 \r
   @param  FirstString   Pointer to a Null-terminated Unicode string.\r
   @param  SecondString  Pointer to a Null-terminated Unicode string.\r
@@ -229,7 +239,7 @@ StrCmp (
   )\r
 {\r
   //\r
-  // ASSERT both strings are less long than PcdMaximumUnicodeStringLength\r
+  // ASSERT both strings should never be zero\r
   //\r
   ASSERT (StrSize (FirstString) != 0);\r
   ASSERT (StrSize (SecondString) != 0);\r
@@ -254,10 +264,6 @@ StrCmp (
 \r
   If FirstString is NULL, then ASSERT().\r
   If SecondString is NULL, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
 \r
   @param  FirstString   Pointer to a Null-terminated Unicode string.\r
   @param  SecondString  Pointer to a Null-terminated Unicode string.\r
@@ -280,8 +286,7 @@ StrnCmp (
   }\r
 \r
   //\r
-  // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.\r
-  // Length tests are performed inside StrLen().\r
+  // ASSERT both strings should never be zero\r
   //\r
   ASSERT (StrSize (FirstString) != 0);\r
   ASSERT (StrSize (SecondString) != 0);\r
@@ -310,13 +315,6 @@ StrnCmp (
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r
-  and Source results in a Unicode string with more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated Unicode string.\r
   @param  Source      Pointer to a Null-terminated Unicode string.\r
@@ -335,7 +333,6 @@ StrCat (
 \r
   //\r
   // Size of the resulting string should never be zero.\r
-  // PcdMaximumUnicodeStringLength is tested inside StrLen().\r
   //\r
   ASSERT (StrSize (Destination) != 0);\r
   return Destination;\r
@@ -357,13 +354,6 @@ StrCat (
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r
-  and Source results in a Unicode string with more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated Unicode string.\r
   @param  Source      Pointer to a Null-terminated Unicode string.\r
@@ -385,7 +375,6 @@ StrnCat (
 \r
   //\r
   // Size of the resulting string should never be zero.\r
-  // PcdMaximumUnicodeStringLength is tested inside StrLen().\r
   //\r
   ASSERT (StrSize (Destination) != 0);\r
   return Destination;\r
@@ -402,8 +391,6 @@ StrnCat (
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and Source contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated ASCII string.\r
   @param  Source      Pointer to a Null-terminated ASCII string.\r
@@ -454,8 +441,6 @@ AsciiStrCpy (
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated ASCII string.\r
   @param  Source      Pointer to a Null-terminated ASCII string.\r
@@ -501,43 +486,6 @@ AsciiStrnCpy (
   return ReturnValue;\r
 }\r
 \r
-/**\r
-  Returns the length of a Null-terminated ASCII string.\r
-\r
-  This function returns the number of ASCII characters in the Null-terminated\r
-  ASCII string specified by String.\r
-\r
-  If String is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and String contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-\r
-  @param  String  Pointer to a Null-terminated ASCII string.\r
-\r
-  @return The length of String.\r
-\r
-**/\r
-UINTN\r
-EFIAPI\r
-AsciiStrLen (\r
-  IN      CONST CHAR8               *String\r
-  )\r
-{\r
-  UINTN                             Length;\r
-\r
-  ASSERT (String != NULL);\r
-\r
-  for (Length = 0; *String != '\0'; String++, Length++) {\r
-    //\r
-    // If PcdMaximumUnicodeStringLength is not zero,\r
-    // length should not more than PcdMaximumUnicodeStringLength\r
-    //\r
-    if (FixedPcdGet32 (PcdMaximumAsciiStringLength) != 0) {\r
-      ASSERT (Length < FixedPcdGet32 (PcdMaximumAsciiStringLength));\r
-    }\r
-  }\r
-  return Length;\r
-}\r
-\r
 /**\r
   Returns the size of a Null-terminated ASCII string in bytes, including the\r
   Null terminator.\r
@@ -546,8 +494,6 @@ AsciiStrLen (
   specified by String.\r
 \r
   If String is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and String contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
 \r
   @param  String  Pointer to a Null-terminated ASCII string.\r
 \r
@@ -575,10 +521,6 @@ AsciiStrSize (
 \r
   If FirstString is NULL, then ASSERT().\r
   If SecondString is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and SecondString contains more\r
-  than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
 \r
   @param  FirstString   Pointer to a Null-terminated ASCII string.\r
   @param  SecondString  Pointer to a Null-terminated ASCII string.\r
@@ -595,7 +537,7 @@ AsciiStrCmp (
   )\r
 {\r
   //\r
-  // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r
+  // ASSERT both strings should never be zero\r
   //\r
   ASSERT (AsciiStrSize (FirstString));\r
   ASSERT (AsciiStrSize (SecondString));\r
@@ -631,10 +573,6 @@ AsciiToUpper (
 \r
   If FirstString is NULL, then ASSERT().\r
   If SecondString is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and SecondString contains more\r
-  than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
 \r
   @param  FirstString   Pointer to a Null-terminated ASCII string.\r
   @param  SecondString  Pointer to a Null-terminated ASCII string.\r
@@ -653,7 +591,7 @@ AsciiStriCmp (
   )\r
 {\r
   //\r
-  // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r
+  // ASSERT both strings should never be zero\r
   //\r
   ASSERT (AsciiStrSize (FirstString));\r
   ASSERT (AsciiStrSize (SecondString));\r
@@ -680,10 +618,6 @@ AsciiStriCmp (
 \r
   If FirstString is NULL, then ASSERT().\r
   If SecondString is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and SecondString contains more\r
-  than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
 \r
   @param  FirstString   Pointer to a Null-terminated ASCII string.\r
   @param  SecondString  Pointer to a Null-terminated ASCII string.\r
@@ -701,7 +635,7 @@ AsciiStrnCmp (
   )\r
 {\r
   //\r
-  // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r
+  // ASSERT both strings should never be zero\r
   //\r
   ASSERT (AsciiStrSize (FirstString));\r
   ASSERT (AsciiStrSize (SecondString));\r
@@ -727,13 +661,6 @@ AsciiStrnCmp (
 \r
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and Destination contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and Source contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero and concatenating Destination and\r
-  Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
-  ASCII characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated ASCII string.\r
   @param  Source      Pointer to a Null-terminated ASCII string.\r
@@ -752,7 +679,6 @@ AsciiStrCat (
 \r
   //\r
   // Size of the resulting string should never be zero.\r
-  // PcdMaximumUnicodeStringLength is tested inside StrLen().\r
   //\r
   ASSERT (AsciiStrSize (Destination) != 0);\r
   return Destination;\r
@@ -774,13 +700,6 @@ AsciiStrCat (
   If Destination is NULL, then ASSERT().\r
   If Source is NULL, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and Destination contains more\r
-  than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r
-  PcdMaximumAsciiStringLength ASCII characters, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and\r
-  Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
-  ASCII characters, then ASSERT().\r
 \r
   @param  Destination Pointer to a Null-terminated ASCII string.\r
   @param  Source      Pointer to a Null-terminated ASCII string.\r
@@ -802,7 +721,6 @@ AsciiStrnCat (
 \r
   //\r
   // Size of the resulting string should never be zero.\r
-  // PcdMaximumUnicodeStringLength is tested inside StrLen().\r
   //\r
   ASSERT (AsciiStrSize (Destination) != 0);\r
   return Destination;\r