|
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 RegExTranslatorHex : RegExTranslatorBase |
|
28 { |
|
29 #region Constructors |
|
30 public RegExTranslatorHex() |
|
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 == 'X' ) |
|
43 { |
|
44 // Build the regular expression |
|
45 StringBuilder regex = new StringBuilder( "[A-Fa-f0-9]" ); |
|
46 if ( m.Width != RegExTranslatorExtractionInfo.KNoWidthSpecified ) |
|
47 { |
|
48 // Add specific length suffix |
|
49 regex.Append( "{" ); |
|
50 regex.Append( m.Width.ToString() ); |
|
51 regex.Append( "}" ); |
|
52 } |
|
53 else |
|
54 { |
|
55 // Add "one or more" suffix |
|
56 regex.Append( "+" ); |
|
57 } |
|
58 |
|
59 ret = CreateField( regex.ToString(), m.Name, m.ValueType, m.CapturePos, m.CaptureLength, true ); |
|
60 ret.FormatSpecifier.NumberBase = m.NumberBase; |
|
61 } |
|
62 // |
|
63 return ret; |
|
64 } |
|
65 #endregion |
|
66 |
|
67 #region Properties |
|
68 #endregion |
|
69 |
|
70 #region Internal methods |
|
71 #endregion |
|
72 |
|
73 #region Internal constants |
|
74 #endregion |
|
75 |
|
76 #region From System.Object |
|
77 public override string ToString() |
|
78 { |
|
79 return base.ToString(); |
|
80 } |
|
81 #endregion |
|
82 |
|
83 #region Data members |
|
84 /// <summary> |
|
85 /// Regular expression built for C# on: Thu, May 15, 2008, 11:33:33 AM |
|
86 /// Using Expresso Version: 3.0.2766, http://www.ultrapico.com |
|
87 /// |
|
88 /// A description of the regular expression: |
|
89 /// |
|
90 /// % |
|
91 /// [PadChar]: A named capture group. [(?:0| )?] |
|
92 /// Match expression but don't capture it. [0| ], zero or one repetitions |
|
93 /// Select from 2 alternatives |
|
94 /// 0 |
|
95 /// Space |
|
96 /// [Width]: A named capture group. [[0-9]?] |
|
97 /// Any character in this class: [0-9], zero or one repetitions |
|
98 /// Match expression but don't capture it. [x|X] |
|
99 /// Select from 2 alternatives |
|
100 /// xX |
|
101 /// |
|
102 /// |
|
103 /// </summary> |
|
104 private static Regex KRegEx = new Regex( |
|
105 "%(?<PadChar>(?:0| )?)(?<Width>[0-9]?)(?:x|X)", |
|
106 RegexOptions.Singleline |
|
107 | RegexOptions.CultureInvariant |
|
108 | RegexOptions.Compiled |
|
109 ); |
|
110 #endregion |
|
111 } |
|
112 } |