Index: BaseTools/Source/Python/AutoGen/UniClassObject.py
===================================================================
--- BaseTools/Source/Python/AutoGen/UniClassObject.py	(revision 16417)
+++ BaseTools/Source/Python/AutoGen/UniClassObject.py	(working copy)
@@ -1,6 +1,9 @@
 ## @file
 # This file is used to collect all defined strings in multiple uni files
 #
+#
+# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<BR>
+#
 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD License
@@ -283,6 +286,20 @@
         FileName = Item[Item.find(u'#include ') + len(u'#include ') :Item.find(u' ', len(u'#include '))][1:-1]
         self.LoadUniFile(FileName)
 
+    def StripComments(self, Line):
+        Comment = u'//'
+        CommentPos = Line.find(Comment)
+        while CommentPos >= 0:
+        # if there are non matched quotes before the comment header
+        # then we are in the middle of a string
+        # but we need to ignore the escaped quotes and backslashes.
+            if ((Line.count(u'"', 0, CommentPos) - Line.count(u'\\"', 0, CommentPos) + Line.count(u'\\\\"', 0, CommentPos)) & 1) == 1:
+                CommentPos = Line.find (Comment, CommentPos + 1)
+            else:
+                return Line[:CommentPos]
+        return Line
+                
+
     #
     # Pre-process before parse .uni file
     #
@@ -291,7 +308,7 @@
             EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path)
 
         try:
-            FileIn = codecs.open(LongFilePath(File.Path), mode='rb', encoding='utf-16').readlines()
+            FileIn = codecs.open(LongFilePath(File.Path), mode='rb', encoding='utf-16')
         except UnicodeError, X:
             EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File.Path);
         except:
@@ -301,36 +318,17 @@
         #
         # Use unique identifier
         #
-        FindFlag = -1
-        LineCount = 0
         for Line in FileIn:
-            Line = FileIn[LineCount]
-            LineCount += 1
             Line = Line.strip()
+            Line = self.StripComments(Line)
+
             #
-            # Ignore comment line and empty line
+            # Ignore empty line
             #
-            if Line == u'' or Line.startswith(u'//'):
-                continue
+            if len(Line) == 0: 
+                continue 
             
-            #
-            # Process comment embeded in string define lines
-            #
-            FindFlag = Line.find(u'//')
-            if FindFlag != -1:
-                Line = Line.replace(Line[FindFlag:], u' ')
-                if FileIn[LineCount].strip().startswith('#language'):
-                    Line = Line + FileIn[LineCount]
-                    FileIn[LineCount-1] = Line
-                    FileIn[LineCount] = os.linesep
-                    LineCount -= 1
-                    for Index in xrange (LineCount + 1, len (FileIn) - 1):
-                        if (Index == len(FileIn) -1):
-                            FileIn[Index] = os.linesep
-                        else:
-                            FileIn[Index] = FileIn[Index + 1]
-                    continue
-                              
+                             
             Line = Line.replace(u'/langdef', u'#langdef')
             Line = Line.replace(u'/string', u'#string')
             Line = Line.replace(u'/language', u'#language')
@@ -345,7 +343,7 @@
             Line = Line.replace(u'\\n', CR + LF)
             Line = Line.replace(u'\\r', CR)
             Line = Line.replace(u'\\t', u'\t')
-            Line = Line.replace(u'''\"''', u'''"''')
+            Line = Line.replace(u'\\"', u'"') 
             Line = Line.replace(u'\t', u' ')
             Line = Line.replace(u'\u0006', u'\\')
             Line = Line.replace(DOBULE_QUOTED_SPLASH, u'"')
