• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * [The "BSD licence"]
3  * Copyright (c) 2005-2008 Terence Parr
4  * All rights reserved.
5  *
6  * Conversion to C#:
7  * Copyright (c) 2008 Sam Harwell, Pixel Mine, Inc.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 using System;
34 using System.Text;
35 
36 namespace Antlr.Runtime.JavaExtensions
37 {
38     public static class StringExtensions
39     {
40 #if DEBUG
41         [Obsolete]
charAt( string str, int index )42         public static char charAt( string str, int index )
43         {
44             return str[index];
45         }
46 
47         [Obsolete]
endsWith( string str, string value )48         public static bool endsWith( string str, string value )
49         {
50             return str.EndsWith( value );
51         }
52 
53         [Obsolete]
indexOf( string str, char value )54         public static int indexOf( string str, char value )
55         {
56             return str.IndexOf( value );
57         }
58 
59         [Obsolete]
indexOf( string str, char value, int startIndex )60         public static int indexOf( string str, char value, int startIndex )
61         {
62             return str.IndexOf( value, startIndex );
63         }
64 
65         [Obsolete]
indexOf( string str, string value )66         public static int indexOf( string str, string value )
67         {
68             return str.IndexOf( value );
69         }
70 
71         [Obsolete]
indexOf( string str, string value, int startIndex )72         public static int indexOf( string str, string value, int startIndex )
73         {
74             return str.IndexOf( value, startIndex );
75         }
76 
77         [Obsolete]
lastIndexOf( string str, char value )78         public static int lastIndexOf( string str, char value )
79         {
80             return str.LastIndexOf( value );
81         }
82 
83         [Obsolete]
lastIndexOf( string str, string value )84         public static int lastIndexOf( string str, string value )
85         {
86             return str.LastIndexOf( value );
87         }
88 
89         [Obsolete]
length( string str )90         public static int length( string str )
91         {
92             return str.Length;
93         }
94 #endif
95 
replace( string str, char oldValue, char newValue )96         public static string replace( string str, char oldValue, char newValue )
97         {
98             int index = str.IndexOf( oldValue );
99             if ( index == -1 )
100                 return str;
101 
102             System.Text.StringBuilder builder = new StringBuilder( str );
103             builder[index] = newValue;
104             return builder.ToString();
105         }
106 
replaceAll( string str, string regex, string newValue )107         public static string replaceAll( string str, string regex, string newValue )
108         {
109             return System.Text.RegularExpressions.Regex.Replace( str, regex, newValue );
110         }
111 
replaceFirst( string str, string regex, string replacement )112         public static string replaceFirst( string str, string regex, string replacement )
113         {
114             return System.Text.RegularExpressions.Regex.Replace( str, regex, replacement );
115         }
116 
117 #if DEBUG
118         [Obsolete]
startsWith( string str, string value )119         public static bool startsWith( string str, string value )
120         {
121             return str.StartsWith( value );
122         }
123 #endif
124 
125         [Obsolete]
substring( string str, int startOffset )126         public static string substring( string str, int startOffset )
127         {
128             return str.Substring( startOffset );
129         }
130 
substring( string str, int startOffset, int endOffset )131         public static string substring( string str, int startOffset, int endOffset )
132         {
133             return str.Substring( startOffset, endOffset - startOffset );
134         }
135 
136 #if DEBUG
137         [Obsolete]
toCharArray( string str )138         public static char[] toCharArray( string str )
139         {
140             return str.ToCharArray();
141         }
142 
143         [Obsolete]
toUpperCase( string str )144         public static string toUpperCase( string str )
145         {
146             return str.ToUpperInvariant();
147         }
148 
149         [Obsolete]
trim( string str )150         public static string trim( string str )
151         {
152             return str.Trim();
153         }
154 #endif
155     }
156 }
157