
1 // 2 // Copyright (c) 2007, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 26 Dec 07 Brian Frank Creation 7 // 8 9 ** 10 ** Regex represents a regular expression. 11 ** 12 const final class Regex 13 { 14 15 ////////////////////////////////////////////////////////////////////////// 16 // Construction 17 ////////////////////////////////////////////////////////////////////////// 18 19 ** 20 ** Compile a regular expression pattern string. 21 ** 22 new fromStr(Str pattern) 23 24 ** 25 ** Private constructor. 26 ** 27 private new make() 28 29 ////////////////////////////////////////////////////////////////////////// 30 // Obj Overrides 31 ////////////////////////////////////////////////////////////////////////// 32 33 ** 34 ** Equality is based on pattern string. 35 ** 36 override Bool equals(Obj obj) 37 38 ** 39 ** Return 'toStr.hash'. 40 ** 41 override Int hash() 42 43 ** 44 ** Return the regular expression pattern string. 45 ** 46 override Str toStr() 47 48 ////////////////////////////////////////////////////////////////////////// 49 // Methods 50 ////////////////////////////////////////////////////////////////////////// 51 52 ** 53 ** Convenience for [matcher(s).matches]`RegexMatcher.matches`. 54 ** 55 Bool matches(Str s) 56 57 ** 58 ** Return a 'RegexMatcher' instance to use for matching 59 ** operations against the specified string. 60 ** 61 RegexMatcher matcher(Str s) 62 63 ** 64 ** Split the specified string around matches of this pattern. 65 ** The 'limit' parameter specifies how many times to apply 66 ** the pattern: 67 ** - If 'limit' is greater than zero, the pattern is applied 68 ** at most 'limit-1' times and any remaining input will 69 ** be returned as the list's last item. 70 ** - If 'limit' is less than zero, then the pattern is 71 ** matched as many times as possible. 72 ** - If 'limit' is zero, then the pattern is matched as many 73 ** times as possible, but trailing empty strings are 74 ** discarded. 75 ** 76 Str[] split(Str s, Int limit := 0) 77 78 79 // TODO: flags support 80 // TODO: examples in fandoc 81 82 }