crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianParserLib/RegExTranslators/Types/RegExTranslatorDecimal.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 using System;
       
    18 using System.Collections.Generic;
       
    19 using System.Text;
       
    20 using System.Text.RegularExpressions;
       
    21 using System.Reflection;
       
    22 using SymbianParserLib.Elements;
       
    23 using SymbianParserLib.Enums;
       
    24 
       
    25 namespace SymbianParserLib.RegExTranslators.Types
       
    26 {
       
    27     internal class RegExTranslatorDecimal : RegExTranslatorBase
       
    28     {
       
    29         #region Constructors
       
    30         public RegExTranslatorDecimal()
       
    31         {
       
    32         }
       
    33         #endregion
       
    34 
       
    35         #region API
       
    36         public override ParserField Process( Capture aCapture, int aStartAt, ParserLine aLine )
       
    37         {
       
    38             ParserField ret = null;
       
    39             //
       
    40             RegExTranslatorExtractionInfo m = new RegExTranslatorExtractionInfo( aLine.OriginalValue, aStartAt );
       
    41             //
       
    42             if ( m.Success && ( m.ValueTypeChar == 'D' || m.ValueTypeChar == 'I' || m.ValueTypeChar == 'U' ) )
       
    43             {
       
    44                 bool requiresNumberedCaptureGroup = true;
       
    45 
       
    46                 // Build the regular expression
       
    47                 StringBuilder regex = new StringBuilder( "[0-9]" );
       
    48                 if ( m.Width != RegExTranslatorExtractionInfo.KNoWidthSpecified )
       
    49                 {
       
    50                     // (?(\b[ 0-9+-]{4}\b:)(?:[ ]{0,3}([+-]?[0-9]{1,4}):))
       
    51                     int width = m.Width;
       
    52                     string padChar = m.PadChar;
       
    53 
       
    54                     // This becomes very complex now. We must match the pad character
       
    55                     regex = new StringBuilder();
       
    56 
       
    57                     // Start a conditional group
       
    58                     regex.Append( "(?" );
       
    59 
       
    60                     // Start the if-statement match. The idea here is to perform a first pass
       
    61                     // that matches any numbers, signs (-/+) and pad characters without any
       
    62                     // care about the ordering. The length, however, is critical.
       
    63                     regex.AppendFormat( "([{0}0-9+-]{{1}})", padChar, width );
       
    64 
       
    65                     // If the match above is true, then we'll execute this 'yes' case. The
       
    66                     // idea now is to pull out the specific value, ignoring the padding.
       
    67 
       
    68                     // We start a non-capturing group. This is the beginning of the value we
       
    69                     // need, but we don't want to capture the padding (although we validate it
       
    70                     // exists).
       
    71                     regex.AppendFormat( "(?:" );
       
    72                     if ( padChar != string.Empty )
       
    73                     {
       
    74                         // We must allow for width-1 pad characters.
       
    75                         regex.AppendFormat( "[{0}]", padChar );
       
    76                         regex.Append( "{0," );
       
    77                         regex.Append( width );
       
    78                         regex.Append( "}" );
       
    79                     }
       
    80 
       
    81                     // We must now allow for a plus/minus sign. We do this within
       
    82                     // a numbered group, since this is the bit we're eventually interested in.
       
    83                     regex.Append( "(" );
       
    84                     regex.Append( "[+-]?[0-9]" );
       
    85                     regex.Append( "{1," + width + "}" );
       
    86                     regex.Append( ")" );
       
    87 
       
    88                     // End non-capturing group
       
    89                     regex.Append( ")" );
       
    90 
       
    91                     // End conditional group
       
    92                     regex.Append( ")" );
       
    93 
       
    94                     // We explicitly managed this ourselves
       
    95                     requiresNumberedCaptureGroup = false;
       
    96                 }
       
    97                 else
       
    98                 {
       
    99                     // Add "one or more" suffix
       
   100                     regex.Append( "+" );
       
   101                 }
       
   102 
       
   103                 ret = CreateField( regex.ToString(), m.Name, m.ValueType, m.CapturePos, m.CaptureLength, requiresNumberedCaptureGroup );
       
   104             }
       
   105             //
       
   106             return ret;
       
   107         }
       
   108         #endregion
       
   109 
       
   110         #region Properties
       
   111         #endregion
       
   112 
       
   113         #region Internal methods
       
   114         #endregion
       
   115 
       
   116         #region Internal constants
       
   117         #endregion
       
   118 
       
   119         #region From System.Object
       
   120         public override string ToString()
       
   121         {
       
   122             return base.ToString();
       
   123         }
       
   124         #endregion
       
   125 
       
   126         #region Data members
       
   127         #endregion
       
   128     }
       
   129 }