Datei: NDODLL/NDOql/Expressions/StringLiteralExpression.cs
Last Commit (f96ae8c)
1 | using System; |
2 | using System.Collections.Generic; |
3 | using System.Text; |
4 | |
5 | namespace NDOql.Expressions |
6 | { |
7 | ····/// <summary> |
8 | ····/// Represents a string literal |
9 | ····/// </summary> |
10 | ····public class StringLiteralExpression : ConstantExpression |
11 | ····{ |
12 | ········/// <summary> |
13 | ········/// Constructor |
14 | ········/// </summary> |
15 | ········/// <param name="value"></param> |
16 | ········/// <param name="line"></param> |
17 | ········/// <param name="col"></param> |
18 | ········public StringLiteralExpression(string value, int line, int col) : base(line, col) |
19 | ········{ |
20 | ············base.Value = value; |
21 | ············base.ExpressionType = ExpressionType.String; |
22 | ········} |
23 | |
24 | ········///<inheritdoc/> |
25 | ········public override string ToString() |
26 | ········{ |
27 | ············return Value.ToString(); |
28 | ············// return "'" + Value + '\''; |
29 | ········} |
30 | |
31 | ········/// <summary> |
32 | ········/// Constructs a clone of the object |
33 | ········/// </summary> |
34 | ········public override OqlExpression DeepClone |
35 | ········{ |
36 | ············get |
37 | ············{ |
38 | ················return new StringLiteralExpression( (string)Value, Line, Column ); |
39 | ············} |
40 | ········} |
41 | ····} |
42 | } |
43 |
New Commit (fe801ed)
1 | using System; |
2 | using System.Collections.Generic; |
3 | using System.Text; |
4 | |
5 | namespace NDOql.Expressions |
6 | { |
7 | ····/// <summary> |
8 | ····/// Represents a string literal |
9 | ····/// </summary> |
10 | ····public class StringLiteralExpression : ConstantExpression |
11 | ····{ |
12 | ········/// <summary> |
13 | ········/// Constructor |
14 | ········/// </summary> |
15 | ········/// <param name="value"></param> |
16 | ········/// <param name="line"></param> |
17 | ········/// <param name="col"></param> |
18 | ········public StringLiteralExpression(string value, int line, int col) : base(line, col) |
19 | ········{ |
20 | ············//CheckForSingleQuotes( value ); |
21 | ············base.Value = value; |
22 | ············base.ExpressionType = ExpressionType.String; |
23 | ········} |
24 | |
25 | ········///// <summary> |
26 | ········///// Converts a string literal, so that it can't contain a single quote. |
27 | ········///// </summary> |
28 | ········///// <param name="value"></param> |
29 | ········///// <returns></returns> |
30 | ········//static void CheckForSingleQuotes( string value ) |
31 | ········//{ |
32 | ········//····var temp = value.Substring( 1, value.Length - 2 ); |
33 | ········//····var sb = new StringBuilder( "'" ); |
34 | ········//····var last = temp.Length - 1; |
35 | ········//····for (int i = 0; i <= last; i++) |
36 | ········//····{ |
37 | ········//········var c = temp[i]; |
38 | ········//········if (c == '\'') |
39 | ········//········{ |
40 | ········//············if (i < last && temp[i + 1] == '\'') |
41 | ········//············{ |
42 | ········//················i++; // Skip second ' |
43 | ········//············} |
44 | ········//············sb.Append( "''" ); // Always append two quotes |
45 | ········//········} |
46 | ········//········else |
47 | ········//········{ |
48 | ········//············sb.Append( c ); |
49 | ········//········} |
50 | ········//····} |
51 | ········//····sb.Append( '\'' ); |
52 | ········//····return sb.ToString(); |
53 | ········//} |
54 | |
55 | ········///<inheritdoc/> |
56 | ········public override string ToString() |
57 | ········{ |
58 | ············return Value.ToString(); |
59 | ············// return "'" + Value + '\''; |
60 | ········} |
61 | |
62 | ········/// <summary> |
63 | ········/// Constructs a clone of the object |
64 | ········/// </summary> |
65 | ········public override OqlExpression DeepClone |
66 | ········{ |
67 | ············get |
68 | ············{ |
69 | ················return new StringLiteralExpression( (string)Value, Line, Column ); |
70 | ············} |
71 | ········} |
72 | ····} |
73 | } |
74 |