## @file\r
# This file is used to define common parsing related functions used in parsing INF/DEC/DSC process\r
#\r
-# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
# 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
List[Key] = [Value]\r
else:\r
List[Key].append(Value)\r
+\r
+## IsValidWord\r
+#\r
+# Check whether the word is valid.\r
+# <Word> ::= (a-zA-Z0-9_)(a-zA-Z0-9_-){0,} Alphanumeric characters with\r
+# optional\r
+# dash "-" and/or underscore "_" characters. No whitespace\r
+# characters are permitted.\r
+#\r
+# @param Word: The word string need to be checked.\r
+#\r
+def IsValidWord(Word):\r
+ if not Word:\r
+ return False\r
+ #\r
+ # The first char should be alpha, _ or Digit.\r
+ #\r
+ if not Word[0].isalnum() and \\r
+ not Word[0] == '_' and \\r
+ not Word[0].isdigit():\r
+ return False\r
+\r
+ LastChar = ''\r
+ for Char in Word[1:]:\r
+ if (not Char.isalpha()) and \\r
+ (not Char.isdigit()) and \\r
+ Char != '-' and \\r
+ Char != '_' and \\r
+ Char != '.':\r
+ return False\r
+ if Char == '.' and LastChar == '.':\r
+ return False\r
+ LastChar = Char\r
+\r
+ return True\r