5 // Chris J Breisch (cjbreisch@altavista.net)
6 // Francesco Delfino (pluto@tipic.com)
7 // Dennis Hayes (dennish@raytek.com)
9 // (C) 2002 Chris J Breisch
10 // 2002 Tipic, Inc. (http://www.tipic.com)
13 * Copyright (c) 2002-2003 Mainsoft Corporation.
14 * Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 * DEALINGS IN THE SOFTWARE.
36 using System
.Globalization
;
38 using System
.ComponentModel
;
40 namespace Microsoft
.VisualBasic
.CompilerServices
{
41 [StandardModule
, EditorBrowsableAttribute(EditorBrowsableState
.Never
)]
42 sealed public class StringType
{
43 private StringType () {}
46 * This method is called when a seconf asterisk appears in the pattern.
47 * @param pattern the relevant part of the original user pattern
48 * @param source the relevanr part of the original user source string
49 * @param count number of characters that where skipped due to the first
51 * @param compareOption the comparision method Binary or Text
52 * @return int number of characters that should be skipped due to all the
53 * asterisk that where found.
55 private static int multipleAsteriskSkip(
59 CompareMethod compareOption
) {
62 int length
= (source
== null) ? 0 : source
.Length
;
63 while (count
< length
) {
64 subString
= source
.Substring(length
- count
);
66 isLike
= StrLike(subString
, pattern
, compareOption
);
68 catch /*(Exception exp)*/ {
78 * This method determines the number of characters that can be skipped due to
80 * @param pattern the relevant part of the original user pattern
81 * @param source the relevanr part of the original user source string
82 * @param compareOption the comparision method Binary or Text
83 * @return int number of characters that should be skipped due to all the
84 * asterisk that where found.
87 private static int asteriskSkip(
90 CompareMethod compareOption
) {
91 int sourceLength
= source
.Length
;
92 int numberOfSkipedChars
= 0;
95 bool exactMatch
= false;
97 char currentPatternChar
;
99 //java patternLen = Strings.Len(pattern); /elsewhere patteren.toString is used, why not here?
100 patternLen
= pattern
.Length
;
101 while (patternIndex
< patternLen
) {
103 currentPatternChar
= pattern
[patternIndex
];
104 if (currentPatternChar
== '*') {
105 //if in the original pattern the where two asterisks together the
107 if (numberOfSkipedChars
> 0) {
109 numberOfSkipedChars
=
110 multipleAsteriskSkip(
115 return sourceLength
- numberOfSkipedChars
;
117 sub
= pattern
.Substring(0, patternIndex
);
118 numberOfSkipedChars
=
124 return numberOfSkipedChars
;
127 else if (currentPatternChar
== '[') {
128 sub
= pattern
.Substring(patternIndex
);
129 int skipCharInPattern
= sub
.IndexOf(']');
130 if (skipCharInPattern
< 0)
132 numberOfSkipedChars
++;
133 patternIndex
+= skipCharInPattern
;
135 else if (currentPatternChar
== ']' || currentPatternChar
== '?' ||
136 currentPatternChar
== '#' || currentPatternChar
== '!' ||
137 currentPatternChar
== '-') {
138 numberOfSkipedChars
++;
143 numberOfSkipedChars
++;
147 //this value is returned if there are not more '*' in the pattern
148 return sourceLength
- numberOfSkipedChars
;
151 public static string FromBoolean (bool Value
) {
152 return Convert
.ToString(Value
);
155 public static string FromByte(byte Value
) {
156 return Convert
.ToString(Value
);
159 public static string FromChar(char Value
) {
160 return Convert
.ToString(Value
);
163 private static string FromCharAndCount(char Value
, int count
) {
164 //return StringStaticWrapper.Ctor(Value,count);
165 return Value
.ToString().Substring(0,count
);
168 private static string FromCharArray(char[] Value
) {
169 return new string(Value
);
172 private static string FromCharArraySubset(
176 return new string(Value
, startIndex
, length
);
179 public static string FromDate(DateTime Value
) {
180 //TODO: which is right, Mono or Mainsoft
181 //implmented in mono by
182 //return Convert.ToString(Value);
188 ts
= Value
.TimeOfDay
;
190 //if only the part of the hours ,minute ... is relevant (not day, month,
191 // year) the format is "T"
192 if (lTime
== Value
.Ticks
||
196 return Value
.ToString("T", null);
197 // only the part of day,month and year is relevant , the format is "d".
199 return Value
.ToString("d", null);
200 return Value
.ToString("G", null);
203 public static string FromDecimal(Decimal Value
) {
204 return FromDecimal(Value
, null);
207 public static string FromDecimal(Decimal Value
, NumberFormatInfo NumberFormat
) {
208 return Convert
.ToString(Value
, NumberFormat
);
209 //java code return Value.ToString("G", numberFormat);
212 public static string FromDouble(double Value
) {
213 return Convert
.ToString(Value
);
214 //java return FromDouble(Value, null);
217 public static string FromDouble(double Value
, NumberFormatInfo NumberFormat
) {
218 return Convert
.ToString(Value
,NumberFormat
);
219 //return new ClrDouble(Value).ToString("G");
222 public static string FromInteger(int Value
) {
223 return Value
.ToString();
226 public static string FromLong(long Value
) {
227 return Value
.ToString();
228 //return Convert.ToString(Value);
231 public static string FromShort(short Value
) {
232 return Value
.ToString();
235 public static string FromSingle(float Value
) {
236 return Convert
.ToString(Value
);
237 //return FromSingle(Value, null);
240 public static string FromSingle(float Value
, NumberFormatInfo NumberFormat
) {
241 return Convert
.ToString(Value
,NumberFormat
);
242 //return new ClrSingle(Value).ToString(NumberFormat);
245 public static string FromObject(object Value
) {
250 return (string) Value
;
254 && ((Array
)Value
).Rank
== 1)
255 return new string(CharArrayType
.FromObject(Value
));
257 return Convert
.ToString(Value
);
263 * This method replace in the reference strDesRef parameter the characters
264 * from position startPosition. the number of characters that are been replaced
265 * is the minimum between maxInsertLength and the length of sInsert.
266 * @param strDesRef the destination string reference.
267 * @param startPosition the index from which the change should be done.
268 * @param maxInsertLength the maximum number of characters that should be change.
269 * @param sInsert the string from which the character should be taken
272 public static void MidStmtStr(ref string strDesRef
, int startPosition
, int maxInsertLength
, string sInsert
)
276 string dest
= strDesRef
;
279 destLen
= dest
.Length
;
281 insertLen
= sInsert
.Length
;
285 //change to java location in array.
286 startPosition
= startPosition
- 1;
287 if (startPosition
< 0 || startPosition
>= destLen
) {
288 throw new ArgumentException("Invalid Argument Value", "Start");
289 //throw new IllegalArgumentException(//java
290 // Utils.GetResourceString("Argument_InvalidValue1", "Start"));
292 if (maxInsertLength
< 0) {
293 throw new ArgumentException("Invalid Argument Value", "Length");
294 //throw new IllegalArgumentException(//java
295 // Utils.GetResourceString("Argument_InvalidValue1", "Length"));
297 if (insertLen
> maxInsertLength
)
298 insertLen
= maxInsertLength
;
299 if (insertLen
> destLen
- startPosition
)
300 insertLen
= destLen
- startPosition
;
303 //TODO: are the next two lines equvlent to the 8 that follow?
304 dest
.Remove(startPosition
,insertLen
);
305 dest
.Insert(startPosition
,sInsert
.Substring(0,insertLen
));
307 //sb = new StringBuilder(dest);
308 //if (sInsert.Length == insertLen)
309 // sb.Replace(startPosition ,startPosition + insertLen, sInsert);
313 // startPosition + insertLen,
314 // sInsert.Substring(0, insertLen));
317 //strDesRef.setValue(sb.ToString());//java
318 strDesRef
= dest
;//sb.ToString();
321 public static int StrCmp(string sLeft
, string sRight
, bool TextCompare
) {
328 return string.Compare(sLeft
, sRight
, TextCompare
);
329 //return StringStaticWrapper.Compare(sLeft, sRight, TextCompare);
330 return sLeft
.CompareTo(sRight
);
331 // return StringStaticWrapper.CompareOrdinal(sLeft, sRight);
334 internal static string ToHalfwidthNumbers(string s
) {
338 private static bool compareBinary(
343 // if (seenNot ^ notMatch ) == true then a previous pattern character
344 // matched the current source character . the current comparision is not
346 if (seenNot ^ match
)
348 else if (seenNot
&& match
)
349 return patternChar
!= sourceChar
;
351 return patternChar
== sourceChar
;
354 private static bool compare(
359 // if (seenNot ^ notMatch ) == true then a previous pattern character
360 // matched the current source character . the current comparision is not
362 //if (seenNot ^ match )
363 if (seenNot
|| match
)
365 else if (seenNot
&& match
)
366 return string.Compare(FromChar(patternChar
), FromChar(sourceChar
)) != 0;
367 //return StringStaticWrapper.Compare(FromChar(patternChar), FromChar(sourceChar)) != 0;
369 return string.Compare(FromChar(patternChar
), FromChar(sourceChar
)) == 0;
370 // return StringStaticWrapper.Compare(FromChar(patternChar), FromChar(sourceChar)) != 0;
371 // return StringStaticWrapper.Compare(FromChar(patternChar), FromChar(sourceChar)) != 0;
373 // return StringStaticWrapper.Compare(FromChar(patternChar), FromChar(sourceChar)) == 0;
377 * check if a specified string is an hex or oct representation of
379 * @param Value The string Value
380 * @param res a long array (minimum size 1).
381 * @return true if <code>Value<\code> can be parse into integer Value.
382 * the result of parsing is located in the <code>res[0]<\code>.
384 internal static bool IsHexOrOctValue(string Value
, long[] res
) {
386 // if the string starts with '&h' or '&H' it represents an Hex number
387 if (Value
.StartsWith("&H") || Value
.StartsWith("&h"))
388 res
[0] = Convert
.ToInt64(Value
.Substring(2), 16);
389 // if the string starts with '&o' or '&O' it represents an Oct number
390 else if (Value
.StartsWith("&O") || Value
.StartsWith("&o"))
391 res
[0] = Convert
.ToInt64(Value
.Substring(2), 8);
395 catch /*(Java catches NumberFormatException, presumable passing all other excptions back up to the caller
396 * //TODO: we should narrow the ececptions that we catch here)*/
398 //catch (NumberFormatException e) {
405 * This method matches a pattern between brackets and the relevant character.
406 * The pattern matching is for binary comparision
407 * @param pattern the part of the pattern that is between the brackets without
409 * @param sourceChar the relevant character in the source string
410 * @return bool true if the character matches the pattern and false otherwise.
412 private static bool inBracketBinary(string pattern
, char sourceChar
) {
413 char currentPatternChar
= (char)0;
414 char currentCharInRange
= (char)0;
415 char previousCharInRange
= (char)0;
416 int patternIndex
= 0;
417 bool isMatch
= false;
418 bool isNotSignAppears
= false;
419 bool specialChar
= false;
420 bool isRangeSignAppears
= false;
421 int patternLength
= (pattern
== null)? 0 : pattern
.Length
;
422 while (patternIndex
< patternLength
) {
423 currentPatternChar
= pattern
[patternIndex
];
424 if (currentPatternChar
== '*') {
433 else if (currentPatternChar
== '?') {
434 // the pattern is '[previousCharInRange-?
435 if (isRangeSignAppears
) {
436 isRangeSignAppears
= false;
437 currentCharInRange
= currentPatternChar
;
438 if (previousCharInRange
> currentCharInRange
)
439 throw new Exception("Bad patteren string");
440 //throw (Exception) ExceptionUtils.VbMakeException(
441 // vbErrors.BadPatStr);
442 //when the previous char in the range matches the char in
444 if (!(isNotSignAppears
|| isMatch
)){
445 if (sourceChar
== previousCharInRange
)
447 if (isNotSignAppears
)
451 //the first place in the range '[?'
453 previousCharInRange
= currentPatternChar
;
463 else if (currentPatternChar
== '#') {
464 //the pattern is like '[previousCharInRange-#'
465 if (isRangeSignAppears
) {
466 isRangeSignAppears
= false;
467 currentCharInRange
= currentPatternChar
;
468 if (previousCharInRange
> currentCharInRange
)
469 throw new Exception("Bad patteren string");
471 // Exception) ExceptionUtils.VbMakeException(
472 // vbErrors.BadPatStr);
473 //when the previous char in the range matches the char in
475 if (!(isNotSignAppears
|| isMatch
)){
476 if (sourceChar
== previousCharInRange
)
478 if (isNotSignAppears
)
482 //the first place in range.
484 previousCharInRange
= currentPatternChar
;
494 else if (currentPatternChar
== '-') {
495 //this pattern is not valid example is '[9--'
496 if (isRangeSignAppears
&& specialChar
)
497 throw new ArgumentException(Utils
.GetResourceString("Argument_InvalidValue1", "Pattern"));
498 if (!(specialChar
) && !(isRangeSignAppears
)) {
500 compareBinary(isNotSignAppears
, isMatch
, currentPatternChar
, sourceChar
);
502 isRangeSignAppears
= true;
504 else if (currentPatternChar
== '!') {
505 //this is the first symbol is the range
506 if (!(isNotSignAppears
)) {
507 isNotSignAppears
= true;
510 //this is the second '!' in the range '[!! ' or appears
511 //as a symbol in the pattern
515 compareBinary(isNotSignAppears
, isMatch
, currentPatternChar
, sourceChar
);
518 else if (currentPatternChar
== '[') {
519 if (isRangeSignAppears
) {
520 isRangeSignAppears
= false;
521 currentCharInRange
= currentPatternChar
;
522 if (previousCharInRange
> currentCharInRange
)
523 throw new Exception("Bad patteren string");
525 // Exception) ExceptionUtils.VbMakeException(
526 // vbErrors.BadPatStr);
527 //when the previous char in the range matches the char in
529 if (!(isNotSignAppears ^ isMatch
)){
530 if (sourceChar
== previousCharInRange
)
532 if (isNotSignAppears
)
536 //the first sign in the range of chars
538 previousCharInRange
= currentPatternChar
;
548 else if (currentPatternChar
== ']') {
558 //this pattern char appears in range of chars.
561 if (isRangeSignAppears
) {
562 isRangeSignAppears
= false;
563 currentCharInRange
= currentPatternChar
;
564 if (previousCharInRange
> currentCharInRange
)
565 throw new Exception("Bad patteren string");
566 //throw (Exception)ExceptionUtils.VbMakeException(vbErrors.BadPatStr);
567 if (!(isNotSignAppears
|| isMatch
)){
568 if (sourceChar
<= previousCharInRange
|| sourceChar
> currentCharInRange
)
572 if (isNotSignAppears
)
577 previousCharInRange
= currentPatternChar
;
579 compareBinary(isNotSignAppears
, isMatch
, currentPatternChar
, sourceChar
);
585 if (isNotSignAppears ^ isMatch
) return true;
586 if (isRangeSignAppears
&& !isMatch
)
588 else if (isNotSignAppears
) {
589 if ('!' != sourceChar
)
596 * this method checks if the soutce string matches the pattern according to
597 * binary comparision.
598 * @param source the source string
599 * @param pattern the pattern string
600 * @return bool True if the source match the pattern and false otherwise.
603 public static bool StrLikeBinary(string source
, string pattern
) {
604 bool startRangeSignAppears
= false;
605 bool isMatch
= false;
606 char currentPatternChar
= (char)0;
607 int patternLength
= (char)0;
608 int patternIndex
= (char)0;
609 char currentSourceChar
= (char)0;
610 //bool isRangeSignAppears = false;
611 //bool specialChar = false;
612 bool isNotSignAppears
= false;
613 int numberOfSkipedChars
= 0;
614 int sourceLength
= 0;
618 patternLength
= (pattern
== null)? 0 : pattern
.Length
;
619 sourceLength
= (source
== null)? 0 : source
.Length
;
621 if (sourceIndex
< sourceLength
)
622 currentSourceChar
= source
[sourceIndex
];
623 while (patternIndex
< patternLength
) {
624 currentPatternChar
= pattern
[patternIndex
];
625 if (currentPatternChar
== '*') {
626 numberOfSkipedChars
=
628 pattern
.Substring(patternIndex
+ 1),
629 source
.Substring(sourceIndex
),
630 CompareMethod
.Binary
);
631 if (numberOfSkipedChars
< 0) {
634 if (numberOfSkipedChars
> 0) {
635 sourceIndex
+= numberOfSkipedChars
;
636 if (sourceIndex
< sourceLength
)
637 currentSourceChar
= source
[sourceIndex
];
640 else if (currentPatternChar
== '?') {
642 if (sourceIndex
< sourceLength
)
643 currentSourceChar
= source
[sourceIndex
];
645 else if (currentPatternChar
== '#') {
646 if (!(char.IsDigit(currentSourceChar
)))
649 if (sourceIndex
< sourceLength
)
650 currentSourceChar
= source
[sourceIndex
];
652 else if (currentPatternChar
== '-') {
660 if (sourceIndex
< sourceLength
)
661 currentSourceChar
= source
[sourceIndex
];
662 //isRangeSignAppears = true;
664 else if (currentPatternChar
== '!') {
665 //specialChar = true;
673 if (sourceIndex
< sourceLength
)
674 currentSourceChar
= source
[sourceIndex
];
676 else if (currentPatternChar
== '[') {
677 string sub
= pattern
.Substring(patternIndex
);
678 int indexOfEndBracket
= sub
.IndexOf(']');
679 startRangeSignAppears
= true;
680 if (indexOfEndBracket
== -1)
682 sub
= sub
.Substring(1, indexOfEndBracket
);
683 startRangeSignAppears
= false;
684 bool isOk
= inBracketBinary(sub
, currentSourceChar
);
688 if (sourceIndex
< sourceLength
)
689 currentSourceChar
= source
[sourceIndex
];
690 patternIndex
+= (sub
.Length
+ 2);
693 else if (currentPatternChar
== ']') {
703 if (sourceIndex
< sourceLength
)
704 currentSourceChar
= source
[sourceIndex
];
706 //specialChar = false;
707 isNotSignAppears
= false;
708 //isRangeSignAppears = false;
710 else if (currentPatternChar
== currentSourceChar
|| isNotSignAppears
) {
711 //specialChar = true;
712 isNotSignAppears
= false;
714 if (sourceIndex
< sourceLength
)
715 currentSourceChar
= source
[sourceIndex
];
716 else if (sourceIndex
> sourceLength
)
724 if (startRangeSignAppears
) {
725 if (sourceLength
== 0)
727 throw new ArgumentException(Utils
.GetResourceString("Argument_InvalidValue1", "Pattern"));
729 if (patternIndex
!= patternLength
|| sourceIndex
!= sourceLength
)
734 public static bool StrLike(
737 CompareMethod compareOption
) {
738 if(compareOption
== CompareMethod
.Text
)
739 return StrLikeBinary(source
, pattern
);
741 return StrLikeText(source
, pattern
);
745 // * this method checks if the soutce string matches the pattern according to
746 // * the comparision method.
747 // * @param source the source string
748 // * @param pattern the pattern string
749 // * @param compareOption this param determines if the comparision is binary
751 // * @return bool True if the source match the pattern and false otherwise.
754 // public static bool StrLike(
757 // int compareOption) {
758 // if (compareOption == 0)
765 * this method checks if the soutce string matches the pattern according to
766 * binary comparision.
767 * @param source the source string
768 * @param pattern the pattern string
769 * @return bool True if the source match the pattern and false otherwise.
772 public static bool StrLikeText(string source
, string pattern
) {
773 //char currentCharInRange = (char)0;
774 bool startRangeSignAppears
= false;
775 bool isMatch
= false;
776 char currentPatternChar
= (char)0;
777 int patternLength
= 0;
778 int patternIndex
= 0;
779 char currentSourceChar
= (char)0;
780 //bool isRangeSignAppears = false;
781 //bool specialChar = false;
782 bool isNotSignAppears
= false;
783 int numberOfSkipedChars
= 0;
784 int sourceLength
= 0;
786 //char previousCharInRange = (char)0;
788 patternLength
= (pattern
== null)? 0 : pattern
.Length
;
789 sourceLength
= (source
== null)? 0 : source
.Length
;
791 if (sourceIndex
< sourceLength
)
792 currentSourceChar
= source
[sourceIndex
];
794 while (patternIndex
< patternLength
) {
795 currentPatternChar
= pattern
[patternIndex
];
796 if (currentPatternChar
== '*') {
797 numberOfSkipedChars
=
799 pattern
.Substring(patternIndex
+ 1),
800 source
.Substring(sourceIndex
),
802 if (numberOfSkipedChars
< 0)
804 if (numberOfSkipedChars
> 0) {
805 sourceIndex
+= numberOfSkipedChars
;
806 if (sourceIndex
< sourceLength
)
807 currentSourceChar
= source
[sourceIndex
];
810 else if (currentPatternChar
== '?') {
812 if (sourceIndex
< sourceLength
)
813 currentSourceChar
= source
[sourceIndex
];
815 else if (currentPatternChar
== '#') {
816 if (!(char.IsDigit(currentSourceChar
)))
819 if (sourceIndex
< sourceLength
)
820 currentSourceChar
= source
[sourceIndex
];
822 else if (currentPatternChar
== '-') {
830 if (sourceIndex
< sourceLength
)
831 currentSourceChar
= source
[sourceIndex
];
832 //isRangeSignAppears = true;
834 else if (currentPatternChar
== '!') {
835 //specialChar = true;
843 if (sourceIndex
< sourceLength
)
844 currentSourceChar
= source
[sourceIndex
];
846 else if (currentPatternChar
== '[') {
847 string sub
= pattern
.Substring(patternIndex
);
848 startRangeSignAppears
= true;
849 int indexOfEndBracket
= sub
.IndexOf(']');
850 if (indexOfEndBracket
== -1)
852 sub
= sub
.Substring(1, indexOfEndBracket
);
853 startRangeSignAppears
= false;
854 bool isOk
= inBracketBinary(sub
, currentSourceChar
);
858 if (sourceIndex
< sourceLength
)
859 currentSourceChar
= source
[sourceIndex
];
860 patternIndex
+= (sub
.Length
+ 2);
863 else if (currentPatternChar
== ']') {
870 //specialChar = true;
874 if (sourceIndex
< sourceLength
)
875 currentSourceChar
= source
[sourceIndex
];
877 //specialChar = false;
878 isNotSignAppears
= false;
879 //isRangeSignAppears = false;
882 //specialChar = true;
883 if (!(currentPatternChar
== currentSourceChar
|| isNotSignAppears
))
885 isNotSignAppears
= false;
887 if (sourceIndex
< sourceLength
)
888 currentSourceChar
= source
[sourceIndex
];
889 else if (sourceIndex
> sourceLength
)
894 if (startRangeSignAppears
) {
895 if (sourceLength
== 0)
897 throw new ArgumentException(Utils
.GetResourceString("Argument_InvalidValue1", "Pattern"));
899 if (patternIndex
!= patternLength
|| sourceIndex
!= sourceLength
)
905 * This method matches a pattern between brackets and the relevant character.
906 * The pattern matching is for text comparision
907 * @param pattern the part of the pattern that is between the brackets without
909 * @param sourceChar the relevant character in the source string
910 * @return bool true if the character matches the pattern and false otherwise.
913 private static bool inBracketText(string pattern
, char sourceChar
) {
914 char currentPatternChar
= (char)0;
915 char currentCharInRange
= (char)0;
916 char previousCharInRange
= (char)0;
917 int patternIndex
= 0;
918 bool isMatch
= false;
919 bool isNotSignAppears
= false;
920 bool specialChar
= false;
921 bool isRangeSignAppears
= false;
922 int patternLength
= (pattern
== null)? 0 : pattern
.Length
;
923 while (patternIndex
< patternLength
) {
924 currentPatternChar
= pattern
[patternIndex
];
925 if (currentPatternChar
== '*') {
934 else if (currentPatternChar
== '?') {
935 if (isRangeSignAppears
) {
936 isRangeSignAppears
= false;
937 currentCharInRange
= currentPatternChar
;
938 if (previousCharInRange
> currentCharInRange
)
939 throw new Exception("Bad patteren string");
941 // Exception) ExceptionUtils.VbMakeException(
942 // vbErrors.BadPatStr);
943 //when the previous char in the range matches the char in
945 if (!(isNotSignAppears ^ isMatch
)){
946 if (!(string.Compare(
947 FromChar(previousCharInRange
),
948 FromChar(sourceChar
),
952 FromChar(currentCharInRange
),
953 FromChar(sourceChar
),
957 if (isNotSignAppears
)
958 isMatch
= (isMatch
== false);
961 // the first place in the range '[?'
963 previousCharInRange
= currentPatternChar
;
973 else if (currentPatternChar
== '#') {
974 // the pattern is '[previousCharInRange-#
975 if (isRangeSignAppears
) {
976 isRangeSignAppears
= false;
977 currentCharInRange
= currentPatternChar
;
978 if (previousCharInRange
> currentCharInRange
)
979 throw new Exception("Bad pattern string");
980 //throw (Exception)ExceptionUtils.VbMakeException(vbErrors.BadPatStr);
981 if (!(isNotSignAppears
|| isMatch
)){
982 if (!(string.Compare(
983 FromChar(previousCharInRange
),
984 FromChar(sourceChar
),
988 FromChar(currentCharInRange
),
989 FromChar(sourceChar
),
993 if (isNotSignAppears
)
994 isMatch
= isMatch
== false;
997 // the first place in the range '[#'
999 previousCharInRange
= currentPatternChar
;
1009 else if (currentPatternChar
== '-') {
1010 //this pattern is not valid example is '[9--'
1011 if (isRangeSignAppears
&& specialChar
)
1012 throw new ArgumentException(Utils
.GetResourceString("Argument_InvalidValue1", "Pattern"));
1013 if (!(specialChar
) && !(isRangeSignAppears
)) {
1015 compare(isNotSignAppears
, isMatch
, currentPatternChar
, sourceChar
);
1017 isRangeSignAppears
= true;
1019 else if (currentPatternChar
== '!') {
1020 //this is the first symbol is the range
1021 if (!(isNotSignAppears
)) {
1022 isNotSignAppears
= true;
1025 //this is the second '!' in the range '[!! ' or appears
1026 //as a symbol in the pattern
1030 compare(isNotSignAppears
, isMatch
, currentPatternChar
, sourceChar
);
1033 else if (currentPatternChar
== '[') {
1034 if (isRangeSignAppears
) {
1035 isRangeSignAppears
= false;
1036 currentCharInRange
= currentPatternChar
;
1037 if (previousCharInRange
> currentCharInRange
)
1038 throw new Exception("Bad patteren string");
1040 // Exception) ExceptionUtils.VbMakeException(
1041 // vbErrors.BadPatStr);
1042 //when the previous char in the range matches the char in
1044 if (!(isNotSignAppears
|| isMatch
)){
1045 if (!(string.Compare(
1046 FromChar(previousCharInRange
),
1047 FromChar(sourceChar
),
1051 FromChar(currentCharInRange
),
1052 FromChar(sourceChar
),
1056 if (isNotSignAppears
)
1057 isMatch
= (isMatch
== false);
1060 // the first sign in the range of chars
1062 previousCharInRange
= currentPatternChar
;
1064 isMatch
= compare(isNotSignAppears
,isMatch
,
1065 currentPatternChar
,sourceChar
);
1068 else if (currentPatternChar
== ']') {
1078 //this pattern char appears in range of chars.
1081 if (isRangeSignAppears
) {
1082 isRangeSignAppears
= false;
1083 currentCharInRange
= currentPatternChar
;
1084 if (previousCharInRange
> currentCharInRange
)
1085 throw new Exception("Bad patteren string");
1086 //throw (Exception)ExceptionUtils.VbMakeException(vbErrors.BadPatStr);
1087 if (!(isNotSignAppears ^ isMatch
)){
1088 if (sourceChar
<= previousCharInRange
|| sourceChar
> currentCharInRange
)
1092 if (isNotSignAppears
)
1097 previousCharInRange
= currentPatternChar
;
1099 compare(isNotSignAppears
, isMatch
, currentPatternChar
, sourceChar
);
1105 if (isNotSignAppears
|| isMatch
) return true;
1106 if (isRangeSignAppears
&& !isMatch
)
1108 else if (isNotSignAppears
) {
1109 if ('!' != sourceChar
)