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 namespace Antlr.Runtime.JavaExtensions
34 {
35     using ObsoleteAttribute = System.ObsoleteAttribute;
36     using Regex = System.Text.RegularExpressions.Regex;
37     using StringBuilder = System.Text.StringBuilder;
38 
39     public static class StringExtensions
40     {
41 #if DEBUG
42         [Obsolete]
charAt( this string str, int index )43         public static char charAt( this string str, int index )
44         {
45             return str[index];
46         }
47 
48         [Obsolete]
endsWith( this string str, string value )49         public static bool endsWith( this string str, string value )
50         {
51             return str.EndsWith( value );
52         }
53 
54         [Obsolete]
indexOf( this string str, char value )55         public static int indexOf( this string str, char value )
56         {
57             return str.IndexOf( value );
58         }
59 
60         [Obsolete]
indexOf( this string str, char value, int startIndex )61         public static int indexOf( this string str, char value, int startIndex )
62         {
63             return str.IndexOf( value, startIndex );
64         }
65 
66         [Obsolete]
indexOf( this string str, string value )67         public static int indexOf( this string str, string value )
68         {
69             return str.IndexOf( value );
70         }
71 
72         [Obsolete]
indexOf( this string str, string value, int startIndex )73         public static int indexOf( this string str, string value, int startIndex )
74         {
75             return str.IndexOf( value, startIndex );
76         }
77 
78         [Obsolete]
lastIndexOf( this string str, char value )79         public static int lastIndexOf( this string str, char value )
80         {
81             return str.LastIndexOf( value );
82         }
83 
84         [Obsolete]
lastIndexOf( this string str, string value )85         public static int lastIndexOf( this string str, string value )
86         {
87             return str.LastIndexOf( value );
88         }
89 
90         [Obsolete]
length( this string str )91         public static int length( this string str )
92         {
93             return str.Length;
94         }
95 
96         [Obsolete]
replace(this string str, char oldValue, char newValue)97         public static string replace(this string str, char oldValue, char newValue)
98         {
99             return str.Replace(oldValue, newValue);
100         }
101 #endif
102 
replaceAll( this string str, string regex, string newValue )103         public static string replaceAll( this string str, string regex, string newValue )
104         {
105             return Regex.Replace( str, regex, newValue );
106         }
107 
replaceFirst( this string str, string regex, string replacement )108         public static string replaceFirst( this string str, string regex, string replacement )
109         {
110             return Regex.Replace( str, regex, replacement );
111         }
112 
113 #if DEBUG
114         [Obsolete]
startsWith( this string str, string value )115         public static bool startsWith( this string str, string value )
116         {
117             return str.StartsWith( value );
118         }
119 
120         [Obsolete]
substring( this string str, int startOffset )121         public static string substring( this string str, int startOffset )
122         {
123             return str.Substring( startOffset );
124         }
125 
126         [Obsolete]
substring(this string str, int startOffset, int endOffset)127         public static string substring(this string str, int startOffset, int endOffset)
128         {
129             return str.Substring( startOffset, endOffset - startOffset );
130         }
131 
132         [Obsolete]
toCharArray( this string str )133         public static char[] toCharArray( this string str )
134         {
135             return str.ToCharArray();
136         }
137 
138         [Obsolete]
toUpperCase( this string str )139         public static string toUpperCase( this string str )
140         {
141             return str.ToUpperInvariant();
142         }
143 
144         [Obsolete]
trim( this string str )145         public static string trim( this string str )
146         {
147             return str.Trim();
148         }
149 #endif
150     }
151 }
152