Orb/Doxygen/doc/translator.py
changeset 4 468f4c8d3d5b
parent 0 42188c7ea2d9
--- a/Orb/Doxygen/doc/translator.py	Fri Apr 23 20:47:58 2010 +0100
+++ b/Orb/Doxygen/doc/translator.py	Wed Aug 11 14:49:30 2010 +0100
@@ -16,7 +16,7 @@
   Originally, the script was written in Perl and was known as translator.pl.
   The last Perl version was dated 2002/05/21 (plus some later corrections)
 
-  $Id: translator.py 708 2009-10-04 20:20:24Z dimitri $
+  $Id: translator.py 721 2010-02-16 21:11:17Z dimitri $
   
                                          Petr Prikryl (prikrylp@skil.cz)
                                
@@ -173,7 +173,7 @@
         self.missingMethods = None   # list of prototypes to be implemented
         self.implementedMethods = None  # list of implemented required methods
         self.adaptMinClass = None    # The newest adapter class that can be used
-            
+        self.isDecodedTranslator = None  # Flag related to internal usage of UTF-8    
         
     def __tokenGenerator(self):
         """Generator that reads the file and yields tokens as 4-tuples.
@@ -1094,6 +1094,13 @@
             else:
                 self.missingMethods.append(p)
 
+        # Set the least important note first if the translator is decoded.
+        # If yes, then it means that the implementation should be switched
+        # to UTF-8 later (suggestion).
+        self.isDecodedTranslator = self.classId in self.manager.decodedTranslators
+        if self.isDecodedTranslator:
+            self.note = 'Reimplementation using UTF-8 suggested.'
+            
         # Check whether adapter must be used or suggest the newest one.
         # Change the status and set the note accordingly.
         if self.baseClassId != 'Translator':
@@ -1277,10 +1284,44 @@
         self.numLang = None                   # excluding coupled En-based
         self.doxVersion = None                # Doxygen version
         
+        # Capture the knowledge about translators that are not implemented
+        # to use UTF-8 internally.
+        self.decodedTranslators = self.getDecodedTranslators()
+        
         # Build objects where each one is responsible for one translator.
         self.__build()
         
         
+    def getDecodedTranslators(self):
+        """Parses language.cpp to find what translators do not use UTF-8 yet"""
+        decodedTranslators = []
+        
+        # Regular expression to detect the lines like
+        #     theTranslator=new TranslatorDecoder(new TranslatorSwedish);
+        rex = re.compile(r'^\s*theTranslator\s*=\s*new\s+.*$')
+        
+        # Regular expression to get the (optional) TranslatorDecoder and TranslatorXXX
+        rex2 = re.compile(r'\bTranslator\w+')
+        
+        # Parse the lines in the specific source code.
+        f = open(os.path.join(self.src_path, 'language.cpp'), 'rU')
+        for line in f:
+            if rex.match(line):
+                lst = rex2.findall(line)
+                if lst[0] == 'TranslatorDecoder':
+                    decodedTranslators.append(lst[1])
+        f.close()
+        
+        # Display warning when all translator implementations were converted 
+        # to UTF-8.
+        if len(decodedTranslators) == 0:
+            print 'This script should be updated. All translators do use UTF-8'
+            print 'internally.  The TranslatorDecoder adapter should be removed'
+            print 'from the code and its usage should not be checked any more.'
+            
+        return decodedTranslators
+    
+        
     def __build(self):
         """Find the translator files and build the objects for translators."""