2006-02-29 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / ByteFX.Data / Common / StringUtility.cs
1 // ByteFX.Data data access components for .Net\r
2 // Copyright (C) 2002-2003  ByteFX, Inc.\r
3 //\r
4 // This library is free software; you can redistribute it and/or\r
5 // modify it under the terms of the GNU Lesser General Public\r
6 // License as published by the Free Software Foundation; either\r
7 // version 2.1 of the License, or (at your option) any later version.\r
8 // \r
9 // This library is distributed in the hope that it will be useful,\r
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
12 // Lesser General Public License for more details.\r
13 // \r
14 // You should have received a copy of the GNU Lesser General Public\r
15 // License along with this library; if not, write to the Free Software\r
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
17 \r
18 using System;\r
19 using System.Text;\r
20 using System.Collections;\r
21 using System.Collections.Specialized;\r
22 \r
23 namespace ByteFX.Data.Common\r
24 {\r
25         /// <summary>\r
26         /// Summary description for StringUtility.\r
27         /// </summary>\r
28         public class StringUtility\r
29         {\r
30                 public StringUtility()\r
31                 {\r
32                 }\r
33 \r
34                 public static string[] Split( string src, char delimiter, params char[] quotedelims )\r
35                 {\r
36                         ArrayList               strings = new ArrayList();\r
37                         StringBuilder   sb = new StringBuilder();\r
38                         ArrayList               ar = new ArrayList(quotedelims);\r
39                         char                    quote_open = Char.MinValue;\r
40 \r
41                         foreach (char c in src) \r
42                         {\r
43                                 if (c == delimiter && quote_open == Char.MinValue) \r
44                                 {\r
45                                         strings.Add( sb.ToString() );\r
46                                         sb.Remove( 0, sb.Length );\r
47                                 }\r
48                                         \r
49                                 else if (ar.Contains(c)) \r
50                                 {\r
51                                         if (quote_open == Char.MinValue)\r
52                                                 quote_open = c;\r
53                                         else if (quote_open == c)\r
54                                                 quote_open = Char.MinValue;\r
55                                         sb.Append(c);\r
56                                 }\r
57                                 else\r
58                                         sb.Append( c );\r
59                         }\r
60 \r
61                         if (sb.Length > 0)\r
62                                 strings.Add( sb.ToString());\r
63 \r
64                         return (string[])strings.ToArray(typeof(string));\r
65                 }\r
66         }\r
67 }\r