1324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/*
2324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * [The "BSD licence"]
3324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Copyright (c) 2005-2008 Terence Parr
4324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * All rights reserved.
5324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
6324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Conversion to C#:
7324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Copyright (c) 2008 Sam Harwell, Pixel Mine, Inc.
8324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * All rights reserved.
9324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
10324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Redistribution and use in source and binary forms, with or without
11324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * modification, are permitted provided that the following conditions
12324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * are met:
13324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * 1. Redistributions of source code must retain the above copyright
14324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    notice, this list of conditions and the following disclaimer.
15324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * 2. Redistributions in binary form must reproduce the above copyright
16324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    notice, this list of conditions and the following disclaimer in the
17324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    documentation and/or other materials provided with the distribution.
18324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * 3. The name of the author may not be used to endorse or promote products
19324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    derived from this software without specific prior written permission.
20324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
21324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
32324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
33324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvernamespace Antlr.Runtime.JavaExtensions
34324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{
35324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    using ObsoleteAttribute = System.ObsoleteAttribute;
36324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    using Regex = System.Text.RegularExpressions.Regex;
37324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    using StringBuilder = System.Text.StringBuilder;
38324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
39324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    public static class StringExtensions
40324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    {
41324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#if DEBUG
42324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
43324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static char charAt( this string str, int index )
44324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
45324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str[index];
46324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
47324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
48324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
49324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static bool endsWith( this string str, string value )
50324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
51324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.EndsWith( value );
52324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
53324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
54324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
55324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static int indexOf( this string str, char value )
56324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
57324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.IndexOf( value );
58324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
59324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
60324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
61324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static int indexOf( this string str, char value, int startIndex )
62324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
63324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.IndexOf( value, startIndex );
64324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
65324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
66324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
67324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static int indexOf( this string str, string value )
68324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
69324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.IndexOf( value );
70324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
71324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
72324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
73324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static int indexOf( this string str, string value, int startIndex )
74324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
75324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.IndexOf( value, startIndex );
76324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
77324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
78324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
79324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static int lastIndexOf( this string str, char value )
80324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
81324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.LastIndexOf( value );
82324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
83324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
84324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
85324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static int lastIndexOf( this string str, string value )
86324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
87324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.LastIndexOf( value );
88324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
89324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
90324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
91324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static int length( this string str )
92324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
93324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.Length;
94324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
95324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
96324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
97324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static string replace(this string str, char oldValue, char newValue)
98324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
99324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.Replace(oldValue, newValue);
100324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
101324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#endif
102324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
103324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static string replaceAll( this string str, string regex, string newValue )
104324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
105324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return Regex.Replace( str, regex, newValue );
106324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
107324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
108324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static string replaceFirst( this string str, string regex, string replacement )
109324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
110324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return Regex.Replace( str, regex, replacement );
111324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
112324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
113324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#if DEBUG
114324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
115324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static bool startsWith( this string str, string value )
116324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
117324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.StartsWith( value );
118324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
119324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
120324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
121324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static string substring( this string str, int startOffset )
122324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
123324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.Substring( startOffset );
124324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
125324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
126324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
127324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static string substring(this string str, int startOffset, int endOffset)
128324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
129324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.Substring( startOffset, endOffset - startOffset );
130324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
131324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
132324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
133324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static char[] toCharArray( this string str )
134324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
135324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.ToCharArray();
136324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
137324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
138324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
139324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static string toUpperCase( this string str )
140324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
141324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.ToUpperInvariant();
142324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
143324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
144324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        [Obsolete]
145324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        public static string trim( this string str )
146324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
147324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            return str.Trim();
148324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
149324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#endif
150324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    }
151324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
152