DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlStringExtensions.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Text;
19 
20 namespace Deveel.Data.Sql.Objects {
21  public static class SqlStringExtensions {
22  // Statics for the tokens.
23  private const char ZeroOrMoreChars = '%';
24  private const char OneChar = '_';
25 
26  private static bool IsWildCard(char ch) {
27  return (ch == OneChar || ch == ZeroOrMoreChars);
28  }
29 
30  public static SqlBoolean PatternMatch(this ISqlString pattern, string expression, char escapeChar) {
31  throw new NotImplementedException();
32  }
33 
34  public static SqlString Substring(this ISqlString source, int offset) {
35  return Substring(source, offset, (int)source.Length - offset);
36  }
37 
38  public static SqlString Substring(this ISqlString source, int offset, int count) {
39  if (source == null || source.IsNull)
40  return SqlString.Null;
41 
42  var en = source.GetEnumerator();
43  var sb = new StringBuilder(count);
44 
45  int index = -1;
46  while (en.MoveNext()) {
47  if (++index < offset)
48  continue;
49 
50  sb.Append(en.Current);
51 
52  if (index == count - 1)
53  break;
54  }
55 
56 #if PCL
57  var s = sb.ToString();
58  return new SqlString(s);
59 #else
60  var chars = new char[count];
61  sb.CopyTo(0, chars, 0, count);
62  return new SqlString(chars);
63 #endif
64  }
65 
66  public static SqlNumber IndexOf(this ISqlString pattern, SqlString expression) {
67  // TODO: Implement a version of the Boyer-Moore algorithm over a SQL String
68  throw new NotImplementedException();
69  }
70  }
71 }
static SqlNumber IndexOf(this ISqlString pattern, SqlString expression)
static SqlBoolean PatternMatch(this ISqlString pattern, string expression, char escapeChar)
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
static SqlString Substring(this ISqlString source, int offset)
static SqlString Substring(this ISqlString source, int offset, int count)
Deveel.Data.Sql.Objects.SqlString SqlString
Definition: DataObject.cs:27