[icinga-checkins] icinga.org: icingaweb2/feature/po-file-parser-13011: CatalogParser: Update 5

git at icinga.org git at icinga.org
Mon Nov 14 10:38:21 CET 2016


Module: icingaweb2
Branch: feature/po-file-parser-13011
Commit: cc65b7e9efab720b6c518c7c716e3ae00a9223de
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=cc65b7e9efab720b6c518c7c716e3ae00a9223de

Author: Noah Hilverling <noah.hilverling at netways.de>
Date:   Mon Nov 14 10:34:15 2016 +0100

CatalogParser: Update 5


---

 .../library/Translation/Catalog/CatalogParser.php  |   26 +++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/modules/translation/library/Translation/Catalog/CatalogParser.php b/modules/translation/library/Translation/Catalog/CatalogParser.php
index e67aa1a..81cd36c 100644
--- a/modules/translation/library/Translation/Catalog/CatalogParser.php
+++ b/modules/translation/library/Translation/Catalog/CatalogParser.php
@@ -58,6 +58,13 @@ class CatalogParser
     protected $currentLineNumber = 0;
 
     /**
+     * Position in current stack
+     *
+     * @var int
+     */
+    protected $currentPosition = 0;
+
+    /**
      * Create a new CatalogParser
      *
      * @param   string  $catalogPath    The path to the catalog file to parse
@@ -146,7 +153,8 @@ class CatalogParser
             throw new CatalogParserException(
                 $this->catalogPath,
                 $this->currentLineNumber,
-                'Missing type before ' . $returnedValue
+                1,
+                "Missing type before \"$returnedValue\""
             );
         }
 
@@ -184,6 +192,7 @@ class CatalogParser
                 $line = $this->catalogFile->fgets();
                 $this->currentLineNumber++;
                 $this->currentStack = $line;
+                $this->currentPosition = 0;
                 return true;
             } else {
                 return false;
@@ -226,6 +235,7 @@ class CatalogParser
     {
         $char = $this->currentStack[0];
         $this->currentStack = substr($this->currentStack, 1);
+        $this->currentPosition++;
 
         return $char;
     }
@@ -270,7 +280,8 @@ class CatalogParser
                 throw new CatalogParserException(
                     $this->catalogPath,
                     $this->currentLineNumber,
-                    'Unexpected char ' . $char . ' after #'
+                    2,
+                    "Unexpected char \"$char\" after #"
                 );
         }
     }
@@ -292,8 +303,6 @@ class CatalogParser
      * Handle stack if first two chars were #|
      *
      * @return  array   Contains the key value if successful
-     *
-     * @throws  CatalogParserException  In case of a syntax error
      */
     protected function handlePrevious()
     {
@@ -318,7 +327,9 @@ class CatalogParser
         for ($i = 0; $i < strlen($this->currentStack); $i++) {
             if ($this->currentStack[$i] !== $endPoint || ($i > 0 && $this->currentStack[$i - 1] === '\\')) {
                 $string .= $this->currentStack[$i];
+                $this->currentPosition++;
             } else {
+                $this->currentPosition++;
                 $this->removeCharsFromStack($i + 1);
                 return $string;
             }
@@ -327,7 +338,8 @@ class CatalogParser
         throw new CatalogParserException(
             $this->catalogPath,
             $this->currentLineNumber,
-            "Missing '$endPoint'"
+            $this->currentPosition+1,
+            "Missing \"$endPoint\""
         );
     }
 
@@ -365,7 +377,8 @@ class CatalogParser
                 throw new CatalogParserException(
                     $this->catalogPath,
                     $this->currentLineNumber,
-                    $keyword . ' is not a valid keyword.'
+                    $this->currentPosition - strlen($keyword),
+                    "\"$keyword\" is not a valid keyword"
                 );
         }
     }
@@ -377,6 +390,7 @@ class CatalogParser
      */
     protected function putCharInStack($char)
     {
+        $this->currentPosition--;
         $this->currentStack = $char . $this->currentStack;
     }
 



More information about the icinga-checkins mailing list