LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/comphelper/source/misc - syntaxhighlight.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 242 0.0 %
Date: 2013-07-09 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <unicode/uchar.h>
      22             : #include <comphelper/syntaxhighlight.hxx>
      23             : #include <comphelper/string.hxx>
      24             : 
      25             : // ##########################################################################
      26             : // ATTENTION: all these words need to be in lower case
      27             : // ##########################################################################
      28             : static const char* strListBasicKeyWords[] = {
      29             :     "access",
      30             :     "alias",
      31             :     "and",
      32             :     "any",
      33             :     "append",
      34             :     "as",
      35             :     "attribute",
      36             :     "base",
      37             :     "binary",
      38             :     "boolean",
      39             :     "byref",
      40             :     "byte",
      41             :     "byval",
      42             :     "call",
      43             :     "case",
      44             :     "cdecl",
      45             :     "classmodule",
      46             :     "close",
      47             :     "compare",
      48             :     "compatible",
      49             :     "const",
      50             :     "currency",
      51             :     "date",
      52             :     "declare",
      53             :     "defbool",
      54             :     "defcur",
      55             :     "defdate",
      56             :     "defdbl",
      57             :     "deferr",
      58             :     "defint",
      59             :     "deflng",
      60             :     "defobj",
      61             :     "defsng",
      62             :     "defstr",
      63             :     "defvar",
      64             :     "dim",
      65             :     "do",
      66             :     "double",
      67             :     "each",
      68             :     "else",
      69             :     "elseif",
      70             :     "end",
      71             :     "end enum",
      72             :     "end function",
      73             :     "end if",
      74             :     "end property",
      75             :     "end select",
      76             :     "end sub",
      77             :     "end type",
      78             :     "endif",
      79             :     "enum",
      80             :     "eqv",
      81             :     "erase",
      82             :     "error",
      83             :     "exit",
      84             :     "explicit",
      85             :     "for",
      86             :     "function",
      87             :     "get",
      88             :     "global",
      89             :     "gosub",
      90             :     "goto",
      91             :     "if",
      92             :     "imp",
      93             :     "implements",
      94             :     "in",
      95             :     "input",
      96             :     "integer",
      97             :     "is",
      98             :     "let",
      99             :     "lib",
     100             :     "like",
     101             :     "line",
     102             :     "line input",
     103             :     "local",
     104             :     "lock",
     105             :     "long",
     106             :     "loop",
     107             :     "lprint",
     108             :     "lset",
     109             :     "mod",
     110             :     "name",
     111             :     "new",
     112             :     "next",
     113             :     "not",
     114             :     "object",
     115             :     "on",
     116             :     "open",
     117             :     "option",
     118             :     "optional",
     119             :     "or",
     120             :     "output",
     121             :     "paramarray",
     122             :     "preserve",
     123             :     "print",
     124             :     "private",
     125             :     "property",
     126             :     "public",
     127             :     "random",
     128             :     "read",
     129             :     "redim",
     130             :     "rem",
     131             :     "resume",
     132             :     "return",
     133             :     "rset",
     134             :     "select",
     135             :     "set",
     136             :     "shared",
     137             :     "single",
     138             :     "static",
     139             :     "step",
     140             :     "stop",
     141             :     "string",
     142             :     "sub",
     143             :     "system",
     144             :     "text",
     145             :     "then",
     146             :     "to",
     147             :     "type",
     148             :     "typeof",
     149             :     "until",
     150             :     "variant",
     151             :     "vbasupport",
     152             :     "wend",
     153             :     "while",
     154             :     "with",
     155             :     "withevents",
     156             :     "write",
     157             :     "xor"
     158             : };
     159             : 
     160             : 
     161             : static const char* strListSqlKeyWords[] = {
     162             :     "all",
     163             :     "and",
     164             :     "any",
     165             :     "as",
     166             :     "asc",
     167             :     "avg",
     168             :     "between",
     169             :     "by",
     170             :     "cast",
     171             :     "corresponding",
     172             :     "count",
     173             :     "create",
     174             :     "cross",
     175             :     "delete",
     176             :     "desc",
     177             :     "distinct",
     178             :     "drop",
     179             :     "escape",
     180             :     "except",
     181             :     "exists",
     182             :     "false",
     183             :     "from",
     184             :     "full",
     185             :     "global",
     186             :     "group",
     187             :     "having",
     188             :     "in",
     189             :     "inner",
     190             :     "insert",
     191             :     "intersect",
     192             :     "into",
     193             :     "is",
     194             :     "join",
     195             :     "left",
     196             :     "like",
     197             :     "limit",
     198             :     "local",
     199             :     "match",
     200             :     "max",
     201             :     "min",
     202             :     "natural",
     203             :     "not",
     204             :     "null",
     205             :     "on",
     206             :     "or",
     207             :     "order",
     208             :     "outer",
     209             :     "right",
     210             :     "select",
     211             :     "set",
     212             :     "some",
     213             :     "sum",
     214             :     "table",
     215             :     "temporary",
     216             :     "true",
     217             :     "union",
     218             :     "unique",
     219             :     "unknown",
     220             :     "update",
     221             :     "using",
     222             :     "values",
     223             :     "where"
     224             : };
     225             : 
     226             : 
     227           0 : extern "C" int CDECL compare_strings( const void *arg1, const void *arg2 )
     228             : {
     229           0 :     return strcmp( (char *)arg1, *(char **)arg2 );
     230             : }
     231             : 
     232             : 
     233             : namespace
     234             : {
     235           0 :     static bool isAlpha(sal_Unicode c)
     236             :     {
     237           0 :         if (comphelper::string::isalphaAscii(c))
     238           0 :             return true;
     239           0 :         return u_isalpha(c);
     240             :     }
     241             : }
     242             : 
     243             : // Helper function: test character flag
     244           0 : sal_Bool SimpleTokenizer_Impl::testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags )
     245             : {
     246           0 :     bool bRet = false;
     247           0 :     if( c != 0 && c <= 255 )
     248             :     {
     249           0 :         bRet = ( (aCharTypeTab[c] & nTestFlags) != 0 );
     250             :     }
     251           0 :     else if( c > 255 )
     252             :     {
     253           0 :         bRet = (( CHAR_START_IDENTIFIER | CHAR_IN_IDENTIFIER ) & nTestFlags) != 0
     254           0 :             ? isAlpha(c) : false;
     255             :     }
     256           0 :     return bRet;
     257             : }
     258             : 
     259           0 : void SimpleTokenizer_Impl::setKeyWords( const char** ppKeyWords, sal_uInt16 nCount )
     260             : {
     261           0 :     ppListKeyWords = ppKeyWords;
     262           0 :     nKeyWordCount = nCount;
     263           0 : }
     264             : 
     265           0 : sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType,
     266             :     /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos )
     267             : {
     268           0 :     reType = TT_UNKNOWN;
     269             : 
     270           0 :     rpStartPos = mpActualPos;
     271             : 
     272           0 :     sal_Unicode c = peekChar();
     273           0 :     if( c == CHAR_EOF )
     274           0 :         return sal_False;
     275             : 
     276           0 :     getChar();
     277             : 
     278             :     //*** Go through all possibilities ***
     279             :     // Space?
     280           0 :     if ( (testCharFlags( c, CHAR_SPACE ) == sal_True) )
     281             :     {
     282           0 :         while( testCharFlags( peekChar(), CHAR_SPACE ) == sal_True )
     283           0 :             getChar();
     284             : 
     285           0 :         reType = TT_WHITESPACE;
     286             :     }
     287             : 
     288             :     // Identifier?
     289           0 :     else if ( (testCharFlags( c, CHAR_START_IDENTIFIER ) == sal_True) )
     290             :     {
     291             :         sal_Bool bIdentifierChar;
     292           0 :         do
     293             :         {
     294             :             // Naechstes Zeichen holen
     295           0 :             c = peekChar();
     296           0 :             bIdentifierChar = testCharFlags( c, CHAR_IN_IDENTIFIER );
     297           0 :             if( bIdentifierChar )
     298           0 :                 getChar();
     299             :         }
     300             :         while( bIdentifierChar );
     301             : 
     302           0 :         reType = TT_IDENTIFIER;
     303             : 
     304             :         // Keyword table
     305           0 :         if (ppListKeyWords != NULL)
     306             :         {
     307           0 :             int nCount = mpActualPos - rpStartPos;
     308             : 
     309             :             // No keyword if string contains char > 255
     310           0 :             bool bCanBeKeyword = true;
     311           0 :             for( int i = 0 ; i < nCount ; i++ )
     312             :             {
     313           0 :                 if( rpStartPos[i] > 255 )
     314             :                 {
     315           0 :                     bCanBeKeyword = false;
     316           0 :                     break;
     317             :                 }
     318             :             }
     319             : 
     320           0 :             if( bCanBeKeyword )
     321             :             {
     322           0 :                 OUString aKWString(rpStartPos, nCount);
     323             :                 OString aByteStr = OUStringToOString(aKWString,
     324           0 :                     RTL_TEXTENCODING_ASCII_US).toAsciiLowerCase();
     325           0 :                 if ( bsearch( aByteStr.getStr(), ppListKeyWords, nKeyWordCount, sizeof( char* ),
     326           0 :                                                                         compare_strings ) )
     327             :                 {
     328           0 :                     reType = TT_KEYWORDS;
     329             : 
     330           0 :                     if (aByteStr.equalsL(RTL_CONSTASCII_STRINGPARAM("rem")))
     331             :                     {
     332             :                         // Remove all characters until end of line or EOF
     333           0 :                         sal_Unicode cPeek = peekChar();
     334           0 :                         while( cPeek != CHAR_EOF && testCharFlags( cPeek, CHAR_EOL ) == sal_False )
     335             :                         {
     336           0 :                             c = getChar();
     337           0 :                             cPeek = peekChar();
     338             :                         }
     339             : 
     340           0 :                         reType = TT_COMMENT;
     341             :                     }
     342           0 :                 }
     343             :             }
     344             :         }
     345             :     }
     346             : 
     347             :     // Operator?
     348             :     // only for BASIC '\'' should be a comment, otherwise it is a normal string and handled there
     349           0 :     else if ( ( testCharFlags( c, CHAR_OPERATOR ) == sal_True ) || ( (c == '\'') && (aLanguage==HIGHLIGHT_BASIC)) )
     350             :     {
     351             :         // parameters for SQL view
     352           0 :         if ( (c==':') || (c=='?'))
     353             :         {
     354           0 :             if (c!='?')
     355             :             {
     356             :                 sal_Bool bIdentifierChar;
     357           0 :                 do
     358             :                 {
     359             :                     // Get next character
     360           0 :                     c = peekChar();
     361           0 :                     bIdentifierChar = isAlpha(c);
     362           0 :                     if( bIdentifierChar )
     363           0 :                         getChar();
     364             :                 }
     365             :                 while( bIdentifierChar );
     366             :             }
     367           0 :             reType = TT_PARAMETER;
     368             :         }
     369           0 :         else if (c=='-')
     370             :         {
     371           0 :             sal_Unicode cPeekNext = peekChar();
     372           0 :             if (cPeekNext=='-')
     373             :             {
     374             :                 // Remove all characters until end of line or EOF
     375           0 :                 while( cPeekNext != CHAR_EOF && testCharFlags( cPeekNext, CHAR_EOL ) == sal_False )
     376             :                 {
     377           0 :                     getChar();
     378           0 :                     cPeekNext = peekChar();
     379             :                 }
     380           0 :                 reType = TT_COMMENT;
     381             :             }
     382             :         }
     383           0 :        else if (c=='/')
     384             :        {
     385           0 :            sal_Unicode cPeekNext = peekChar();
     386           0 :            if (cPeekNext=='/')
     387             :            {
     388             :                // Remove all characters until end of line or EOF
     389           0 :                while( cPeekNext != CHAR_EOF && testCharFlags( cPeekNext, CHAR_EOL ) == sal_False )
     390             :                {
     391           0 :                    getChar();
     392           0 :                    cPeekNext = peekChar();
     393             :                }
     394           0 :                reType = TT_COMMENT;
     395             :            }
     396             :        }
     397             :         else
     398             :         {
     399             :             // Comment?
     400           0 :             if ( c == '\'' )
     401             :             {
     402           0 :                 c = getChar();
     403             : 
     404             :                 // Remove all characters until end of line or EOF
     405           0 :                 sal_Unicode cPeek = c;
     406           0 :                 while( cPeek != CHAR_EOF && testCharFlags( cPeek, CHAR_EOL ) == sal_False )
     407             :                 {
     408           0 :                     getChar();
     409           0 :                     cPeek = peekChar();
     410             :                 }
     411             : 
     412           0 :                 reType = TT_COMMENT;
     413             :             }
     414             : 
     415             :             // The real operator; can be easily used since not the actual
     416             :             // operator (e.g. +=) is concerned, but the fact that it is one
     417           0 :             if( reType != TT_COMMENT )
     418             :             {
     419           0 :                 reType = TT_OPERATOR;
     420             :             }
     421             : 
     422             :         }
     423             :     }
     424             : 
     425             :     // Object separator? Must be handled before Number
     426           0 :     else if( c == '.' && ( peekChar() < '0' || peekChar() > '9' ) )
     427             :     {
     428           0 :         reType = TT_OPERATOR;
     429             :     }
     430             : 
     431             :     // Number?
     432           0 :     else if( testCharFlags( c, CHAR_START_NUMBER ) == sal_True )
     433             :     {
     434           0 :         reType = TT_NUMBER;
     435             : 
     436             :         // Number system, 10 = normal, it is changed for Oct/Hex
     437           0 :         int nRadix = 10;
     438             : 
     439             :         // Is it an Oct or a Hex number?
     440           0 :         if( c == '&' )
     441             :         {
     442             :             // Octal?
     443           0 :             if( peekChar() == 'o' || peekChar() == 'O' )
     444             :             {
     445             :                 // remove o
     446           0 :                 getChar();
     447           0 :                 nRadix = 8;     // Octal base
     448             : 
     449             :                 // Read all numbers
     450           0 :                 while( testCharFlags( peekChar(), CHAR_IN_OCT_NUMBER ) )
     451           0 :                     c = getChar();
     452             :             }
     453             :             // Hexadecimal?
     454           0 :             else if( peekChar() == 'h' || peekChar() == 'H' )
     455             :             {
     456             :                 // remove x
     457           0 :                 getChar();
     458           0 :                 nRadix = 16;     // Hexadecimal base
     459             : 
     460             :                 // Read all numbers
     461           0 :                 while( testCharFlags( peekChar(), CHAR_IN_HEX_NUMBER ) )
     462           0 :                     c = getChar();
     463             :             }
     464             :             else
     465             :             {
     466           0 :                 reType = TT_OPERATOR;
     467             :             }
     468             :         }
     469             : 
     470             :         // When it is not Oct or Hex, then it is double
     471           0 :         if( reType == TT_NUMBER && nRadix == 10 )
     472             :         {
     473             :             // Flag if the last character is an exponent
     474           0 :             sal_Bool bAfterExpChar = sal_False;
     475             : 
     476             :             // Read all numbers
     477           0 :             while( testCharFlags( peekChar(), CHAR_IN_NUMBER ) ||
     478           0 :                     (bAfterExpChar && peekChar() == '+' ) ||
     479           0 :                     (bAfterExpChar && peekChar() == '-' ) )
     480             :                     // After exponent +/- are OK, too
     481             :             {
     482           0 :                 c = getChar();
     483           0 :                 bAfterExpChar = ( c == 'e' || c == 'E' );
     484             :             }
     485             :         }
     486             :     }
     487             : 
     488             :     // String?
     489           0 :     else if( testCharFlags( c, CHAR_START_STRING ) == sal_True )
     490             :     {
     491             :         // Remember which character has opened the string
     492           0 :         sal_Unicode cEndString = c;
     493           0 :         if( c == '[' )
     494           0 :             cEndString = ']';
     495             : 
     496             :         // Read all characters
     497           0 :         while( peekChar() != cEndString )
     498             :         {
     499             :             // Detect EOF before getChar(), so we do not loose EOF
     500           0 :             if( peekChar() == CHAR_EOF )
     501             :             {
     502             :                 // ERROR: unterminated string literal
     503           0 :                 reType = TT_ERROR;
     504           0 :                 break;
     505             :             }
     506           0 :             c = getChar();
     507           0 :             if( testCharFlags( c, CHAR_EOL ) == sal_True )
     508             :             {
     509             :                 // ERROR: unterminated string literal
     510           0 :                 reType = TT_ERROR;
     511           0 :                 break;
     512             :             }
     513             :         }
     514             : 
     515           0 :         if( reType != TT_ERROR )
     516             :         {
     517           0 :             getChar();
     518           0 :             if( cEndString == ']' )
     519           0 :                 reType = TT_IDENTIFIER;
     520             :             else
     521           0 :                 reType = TT_STRING;
     522             :         }
     523             :     }
     524             : 
     525             :     // End of line?
     526           0 :     else if( testCharFlags( c, CHAR_EOL ) == sal_True )
     527             :     {
     528             :         // If another EOL character comes, read it
     529           0 :         sal_Unicode cNext = peekChar();
     530           0 :         if( cNext != c && testCharFlags( cNext, CHAR_EOL ) == sal_True )
     531           0 :             getChar();
     532             : 
     533             :         // Set position data at the line start
     534           0 :         nCol = 0;
     535           0 :         nLine++;
     536             : 
     537           0 :         reType = TT_EOL;
     538             :     }
     539             : 
     540             :     // All other will remain TT_UNKNOWN
     541             : 
     542             :     // Save end position
     543           0 :     rpEndPos = mpActualPos;
     544           0 :     return sal_True;
     545             : }
     546             : 
     547           0 : SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLanguage(aLang)
     548             : {
     549           0 :     memset( aCharTypeTab, 0, sizeof( aCharTypeTab ) );
     550             : 
     551             :     // Fill character table
     552             :     sal_uInt16 i;
     553             : 
     554             :     // Allowed characters for identifiers
     555           0 :     sal_uInt16 nHelpMask = (sal_uInt16)( CHAR_START_IDENTIFIER | CHAR_IN_IDENTIFIER );
     556           0 :     for( i = 'a' ; i <= 'z' ; i++ )
     557           0 :         aCharTypeTab[i] |= nHelpMask;
     558           0 :     for( i = 'A' ; i <= 'Z' ; i++ )
     559           0 :         aCharTypeTab[i] |= nHelpMask;
     560           0 :     aCharTypeTab[(int)'_'] |= nHelpMask;
     561           0 :     aCharTypeTab[(int)'$'] |= nHelpMask;
     562             : 
     563             :     // Digit (can be identifier and number)
     564             :     nHelpMask = (sal_uInt16)( CHAR_IN_IDENTIFIER | CHAR_START_NUMBER |
     565           0 :                          CHAR_IN_NUMBER | CHAR_IN_HEX_NUMBER );
     566           0 :     for( i = '0' ; i <= '9' ; i++ )
     567           0 :         aCharTypeTab[i] |= nHelpMask;
     568             : 
     569             :     // Add e, E, . and & here manually
     570           0 :     aCharTypeTab[(int)'e'] |= CHAR_IN_NUMBER;
     571           0 :     aCharTypeTab[(int)'E'] |= CHAR_IN_NUMBER;
     572           0 :     aCharTypeTab[(int)'.'] |= (sal_uInt16)( CHAR_IN_NUMBER | CHAR_START_NUMBER );
     573           0 :     aCharTypeTab[(int)'&'] |= CHAR_START_NUMBER;
     574             : 
     575             :     // Hexadecimal digit
     576           0 :     for( i = 'a' ; i <= 'f' ; i++ )
     577           0 :         aCharTypeTab[i] |= CHAR_IN_HEX_NUMBER;
     578           0 :     for( i = 'A' ; i <= 'F' ; i++ )
     579           0 :         aCharTypeTab[i] |= CHAR_IN_HEX_NUMBER;
     580             : 
     581             :     // Octal digit
     582           0 :     for( i = '0' ; i <= '7' ; i++ )
     583           0 :         aCharTypeTab[i] |= CHAR_IN_OCT_NUMBER;
     584             : 
     585             :     // String literal start/end characters
     586           0 :     aCharTypeTab[(int)'\''] |= CHAR_START_STRING;
     587           0 :     aCharTypeTab[(int)'\"'] |= CHAR_START_STRING;
     588           0 :     aCharTypeTab[(int)'[']  |= CHAR_START_STRING;
     589           0 :     aCharTypeTab[(int)'`']  |= CHAR_START_STRING;
     590             : 
     591             :     // Operator characters
     592           0 :     aCharTypeTab[(int)'!'] |= CHAR_OPERATOR;
     593           0 :     aCharTypeTab[(int)'%'] |= CHAR_OPERATOR;
     594             :     // aCharTypeTab[(int)'&'] |= CHAR_OPERATOR;     Removed because of #i14140
     595           0 :     aCharTypeTab[(int)'('] |= CHAR_OPERATOR;
     596           0 :     aCharTypeTab[(int)')'] |= CHAR_OPERATOR;
     597           0 :     aCharTypeTab[(int)'*'] |= CHAR_OPERATOR;
     598           0 :     aCharTypeTab[(int)'+'] |= CHAR_OPERATOR;
     599           0 :     aCharTypeTab[(int)','] |= CHAR_OPERATOR;
     600           0 :     aCharTypeTab[(int)'-'] |= CHAR_OPERATOR;
     601           0 :     aCharTypeTab[(int)'/'] |= CHAR_OPERATOR;
     602           0 :     aCharTypeTab[(int)':'] |= CHAR_OPERATOR;
     603           0 :     aCharTypeTab[(int)'<'] |= CHAR_OPERATOR;
     604           0 :     aCharTypeTab[(int)'='] |= CHAR_OPERATOR;
     605           0 :     aCharTypeTab[(int)'>'] |= CHAR_OPERATOR;
     606           0 :     aCharTypeTab[(int)'?'] |= CHAR_OPERATOR;
     607           0 :     aCharTypeTab[(int)'^'] |= CHAR_OPERATOR;
     608           0 :     aCharTypeTab[(int)'|'] |= CHAR_OPERATOR;
     609           0 :     aCharTypeTab[(int)'~'] |= CHAR_OPERATOR;
     610           0 :     aCharTypeTab[(int)'{'] |= CHAR_OPERATOR;
     611           0 :     aCharTypeTab[(int)'}'] |= CHAR_OPERATOR;
     612             :     // aCharTypeTab[(int)'['] |= CHAR_OPERATOR;     Removed because of #i17826
     613           0 :     aCharTypeTab[(int)']'] |= CHAR_OPERATOR;
     614           0 :     aCharTypeTab[(int)';'] |= CHAR_OPERATOR;
     615             : 
     616             :     // Space
     617           0 :     aCharTypeTab[(int)' ' ] |= CHAR_SPACE;
     618           0 :     aCharTypeTab[(int)'\t'] |= CHAR_SPACE;
     619             : 
     620             :     // End of line characters
     621           0 :     aCharTypeTab[(int)'\r'] |= CHAR_EOL;
     622           0 :     aCharTypeTab[(int)'\n'] |= CHAR_EOL;
     623             : 
     624           0 :     ppListKeyWords = NULL;
     625           0 : }
     626             : 
     627           0 : SimpleTokenizer_Impl::~SimpleTokenizer_Impl( void )
     628             : {
     629           0 : }
     630             : 
     631           0 : SimpleTokenizer_Impl* getSimpleTokenizer( void )
     632             : {
     633             :     static SimpleTokenizer_Impl* pSimpleTokenizer = NULL;
     634           0 :     if( !pSimpleTokenizer )
     635           0 :         pSimpleTokenizer = new SimpleTokenizer_Impl();
     636           0 :     return pSimpleTokenizer;
     637             : }
     638             : 
     639           0 : sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const OUString* aSource )
     640             : {
     641             :     // Set the position to the beginning of the source string
     642           0 :     mpStringBegin = mpActualPos = aSource->getStr();
     643             : 
     644             :     // Initialize row and column
     645           0 :     nLine = nParseLine;
     646           0 :     nCol = 0L;
     647             : 
     648             :     // Variables for the out parameter
     649             :     TokenTypes eType;
     650             :     const sal_Unicode* pStartPos;
     651             :     const sal_Unicode* pEndPos;
     652             : 
     653             :     // Loop over all the tokens
     654           0 :     sal_uInt16 nTokenCount = 0;
     655           0 :     while( getNextToken( eType, pStartPos, pEndPos ) )
     656           0 :         nTokenCount++;
     657             : 
     658           0 :     return nTokenCount;
     659             : }
     660             : 
     661           0 : void SimpleTokenizer_Impl::getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine,
     662             :                                                     /*out*/HighlightPortions& portions  )
     663             : {
     664             :     // Set the position to the beginning of the source string
     665           0 :     mpStringBegin = mpActualPos = rLine.getStr();
     666             : 
     667             :     // Initialize row and column
     668           0 :     nLine = nParseLine;
     669           0 :     nCol = 0L;
     670             : 
     671             :     // Variables for the out parameter
     672             :     TokenTypes eType;
     673             :     const sal_Unicode* pStartPos;
     674             :     const sal_Unicode* pEndPos;
     675             : 
     676             :     // Loop over all the tokens
     677           0 :     while( getNextToken( eType, pStartPos, pEndPos ) )
     678             :     {
     679             :         HighlightPortion portion;
     680             : 
     681           0 :         portion.nBegin = (sal_uInt16)(pStartPos - mpStringBegin);
     682           0 :         portion.nEnd = (sal_uInt16)(pEndPos - mpStringBegin);
     683           0 :         portion.tokenType = eType;
     684             : 
     685           0 :         portions.push_back(portion);
     686             :     }
     687           0 : }
     688             : 
     689             : 
     690           0 : SyntaxHighlighter::SyntaxHighlighter()
     691             : {
     692           0 :     m_pSimpleTokenizer = 0;
     693           0 :     m_pKeyWords = NULL;
     694           0 :     m_nKeyWordCount = 0;
     695           0 : }
     696             : 
     697           0 : SyntaxHighlighter::~SyntaxHighlighter()
     698             : {
     699           0 :     delete m_pSimpleTokenizer;
     700           0 :     delete m_pKeyWords;
     701           0 : }
     702             : 
     703           0 : void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ )
     704             : {
     705           0 :     eLanguage = eLanguage_;
     706           0 :     delete m_pSimpleTokenizer;
     707           0 :     m_pSimpleTokenizer = new SimpleTokenizer_Impl(eLanguage);
     708             : 
     709           0 :     switch (eLanguage)
     710             :     {
     711             :         case HIGHLIGHT_BASIC:
     712             :             m_pSimpleTokenizer->setKeyWords( strListBasicKeyWords,
     713           0 :                                             sizeof( strListBasicKeyWords ) / sizeof( char* ));
     714           0 :             break;
     715             :         case HIGHLIGHT_SQL:
     716             :             m_pSimpleTokenizer->setKeyWords( strListSqlKeyWords,
     717           0 :                                             sizeof( strListSqlKeyWords ) / sizeof( char* ));
     718           0 :             break;
     719             :         default:
     720           0 :             m_pSimpleTokenizer->setKeyWords( NULL, 0 );
     721             :     }
     722           0 : }
     723             : 
     724           0 : void SyntaxHighlighter::notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference,
     725             :                                 const OUString* pChangedLines, sal_uInt32 nArrayLength)
     726             : {
     727             :     (void)nLineCountDifference;
     728             : 
     729           0 :     for( sal_uInt32 i=0 ; i < nArrayLength ; i++ )
     730           0 :         m_pSimpleTokenizer->parseLine(nLine+i, &pChangedLines[i]);
     731           0 : }
     732             : 
     733           0 : void SyntaxHighlighter::getHighlightPortions( sal_uInt32 nLine, const OUString& rLine,
     734             :                                             /*out*/HighlightPortions& portions )
     735             : {
     736           0 :     m_pSimpleTokenizer->getHighlightPortions( nLine, rLine, portions );
     737           0 : }
     738             : 
     739             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10