/** @file\r
*\r
-* Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
+* Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
* \r
* This program and the accompanying materials \r
* are licensed and made available under the terms and conditions of the BSD License \r
return FALSE;\r
}\r
}\r
+\r
+/*\r
+ * Try to detect if the given string is an ASCII or Unicode string\r
+ *\r
+ * There are actually few limitation to this function but it is mainly to give\r
+ * a user friendly output.\r
+ *\r
+ * Some limitations:\r
+ * - it only supports unicode string that use ASCII character (< 0x100)\r
+ * - single character ASCII strings are interpreted as Unicode string\r
+ * - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)\r
+ *\r
+ * @param String Buffer that might contain a Unicode or Ascii string\r
+ * @param IsUnicode If not NULL this boolean value returns if the string is an\r
+ * ASCII or Unicode string.\r
+ */\r
+BOOLEAN\r
+IsPrintableString (\r
+ IN VOID* String,\r
+ OUT BOOLEAN *IsUnicode\r
+ )\r
+{\r
+ BOOLEAN UnicodeDetected;\r
+ BOOLEAN IsPrintable;\r
+ UINTN Index;\r
+ CHAR16 Character;\r
+\r
+ // We do not support NULL pointer\r
+ ASSERT (String != NULL);\r
+\r
+ // Test empty string\r
+ if (*(CHAR16*)String == L'\0') {\r
+ if (IsUnicode) {\r
+ *IsUnicode = TRUE;\r
+ }\r
+ return TRUE;\r
+ } else if (*(CHAR16*)String == '\0') {\r
+ if (IsUnicode) {\r
+ *IsUnicode = FALSE;\r
+ }\r
+ return TRUE;\r
+ }\r
+\r
+ // Limitation: if the string is an ASCII single character string. This comparison\r
+ // will assume it is a Unicode string.\r
+ if (*(CHAR16*)String < 0x100) {\r
+ UnicodeDetected = TRUE;\r
+ } else {\r
+ UnicodeDetected = FALSE;\r
+ }\r
+\r
+ IsPrintable = FALSE;\r
+ for (Index = 0; Index < BOOT_DEVICE_OPTION_MAX * 2; Index++) {\r
+ if (UnicodeDetected) {\r
+ Character = ((CHAR16*)String)[Index];\r
+ } else {\r
+ Character = ((CHAR8*)String)[Index];\r
+ }\r
+\r
+ if (Character == '\0') {\r
+ // End of the string\r
+ IsPrintable = TRUE;\r
+ break;\r
+ } else if ((Character < 0x20) || (Character > 0x7f)) {\r
+ // We only support the range of printable ASCII character\r
+ IsPrintable = FALSE;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (IsPrintable && IsUnicode) {\r
+ *IsUnicode = UnicodeDetected;\r
+ }\r
+\r
+ return IsPrintable;\r
+}\r
IN VOID* String\r
);\r
\r
+/*\r
+ * Try to detect if the given string is an ASCII or Unicode string\r
+ *\r
+ * There are actually few limitation to this function but it is mainly to give\r
+ * a user friendly output.\r
+ *\r
+ * Some limitations:\r
+ * - it only supports unicode string that use ASCII character (< 0x100)\r
+ * - single character ASCII strings are interpreted as Unicode string\r
+ * - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)\r
+ *\r
+ * @param String Buffer that might contain a Unicode or Ascii string\r
+ * @param IsUnicode If not NULL this boolean value returns if the string is an\r
+ * ASCII or Unicode string.\r
+ */\r
+BOOLEAN\r
+IsPrintableString (\r
+ IN VOID* String,\r
+ OUT BOOLEAN *IsUnicode\r
+ );\r
+\r
#endif /* _BDSINTERNAL_H_ */\r