651
|
1 |
"
|
|
2 |
Copyright (c) 2007-2010 Jan Vrany
|
|
3 |
Copyright (c) 2009-2010 eXept Software AG
|
|
4 |
|
|
5 |
Permission is hereby granted, free of charge, to any person
|
|
6 |
obtaining a copy of this software and associated documentation
|
|
7 |
files (the 'Software'), to deal in the Software without
|
|
8 |
restriction, including without limitation the rights to use,
|
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10 |
copies of the Software, and to permit persons to whom the
|
|
11 |
Software is furnished to do so, subject to the following
|
|
12 |
conditions:
|
|
13 |
|
|
14 |
The above copyright notice and this permission notice shall be
|
|
15 |
included in all copies or substantial portions of the Software.
|
|
16 |
|
|
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
25 |
"
|
|
26 |
"{ Package: 'stx:libsvn' }"
|
|
27 |
|
|
28 |
"{ NameSpace: SVN }"
|
|
29 |
|
|
30 |
Object subclass:#PackagePattern
|
|
31 |
instanceVariableNames:'pattern patternComponents'
|
|
32 |
classVariableNames:''
|
|
33 |
poolDictionaries:''
|
|
34 |
category:'SVN-Private'
|
|
35 |
!
|
|
36 |
|
|
37 |
!PackagePattern class methodsFor:'documentation'!
|
|
38 |
|
|
39 |
copyright
|
|
40 |
"
|
|
41 |
Copyright (c) 2007-2010 Jan Vrany
|
|
42 |
Copyright (c) 2009-2010 eXept Software AG
|
|
43 |
|
|
44 |
Permission is hereby granted, free of charge, to any person
|
|
45 |
obtaining a copy of this software and associated documentation
|
|
46 |
files (the 'Software'), to deal in the Software without
|
|
47 |
restriction, including without limitation the rights to use,
|
|
48 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
49 |
copies of the Software, and to permit persons to whom the
|
|
50 |
Software is furnished to do so, subject to the following
|
|
51 |
conditions:
|
|
52 |
|
|
53 |
The above copyright notice and this permission notice shall be
|
|
54 |
included in all copies or substantial portions of the Software.
|
|
55 |
|
|
56 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
57 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
58 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
59 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
60 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
61 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
62 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
63 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
64 |
|
|
65 |
"
|
|
66 |
! !
|
|
67 |
|
|
68 |
!PackagePattern class methodsFor:'instance creation'!
|
|
69 |
|
|
70 |
for: aString
|
|
71 |
|
|
72 |
^self new setPattern: aString
|
|
73 |
|
|
74 |
"Created: / 12-03-2011 / 20:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
75 |
! !
|
|
76 |
|
|
77 |
!PackagePattern methodsFor:'initialization'!
|
|
78 |
|
|
79 |
setPattern:something
|
|
80 |
pattern := something.
|
|
81 |
self preProcess
|
|
82 |
|
|
83 |
"Created: / 12-03-2011 / 20:58:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
84 |
! !
|
|
85 |
|
|
86 |
!PackagePattern methodsFor:'matching'!
|
|
87 |
|
|
88 |
match: package into: replacements
|
|
89 |
|
|
90 |
| packageComponents start replacementIndex replacementSize |
|
|
91 |
|
|
92 |
"Ugly code warning. Q&D hack"
|
|
93 |
|
|
94 |
packageComponents := (package copyReplaceAll: $: with: $/) tokensBasedOn: $/.
|
|
95 |
start := 1.
|
|
96 |
replacementIndex := 1.
|
|
97 |
replacementSize := replacements size.
|
|
98 |
1 to: patternComponents size do:
|
|
99 |
[:i|
|
|
100 |
start := self matchAt: i into: replacements index: replacementIndex in: packageComponents from: start.
|
|
101 |
replacementSize ~= replacements size ifTrue:
|
|
102 |
[replacementIndex := replacementIndex + 1.
|
|
103 |
replacementSize := replacements size].
|
|
104 |
start ifNil:[^false]].
|
|
105 |
^true.
|
|
106 |
|
|
107 |
"Created: / 12-03-2011 / 21:21:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
108 |
!
|
|
109 |
|
|
110 |
matches: package
|
|
111 |
|
|
112 |
^self match: package into: nil.
|
|
113 |
|
|
114 |
"Created: / 12-03-2011 / 21:20:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
115 |
! !
|
|
116 |
|
|
117 |
!PackagePattern methodsFor:'private'!
|
|
118 |
|
|
119 |
matchAt: componentIdx into: replacements index: replacementIndex in: packageComponents from: start
|
|
120 |
|
|
121 |
| component |
|
|
122 |
component := patternComponents at: componentIdx.
|
|
123 |
component ~= '*' ifTrue:[
|
|
124 |
start > packageComponents size ifTrue:[^nil].
|
|
125 |
(packageComponents at: start) = component
|
|
126 |
ifTrue:[^start + 1]
|
|
127 |
ifFalse:[^nil]
|
|
128 |
] ifFalse:[
|
|
129 |
start > packageComponents size ifTrue:[
|
|
130 |
componentIdx == patternComponents size ifTrue:[
|
|
131 |
replacements ifNotNil:[
|
|
132 |
replacements
|
|
133 |
at: replacementIndex printString
|
|
134 |
put: ''].
|
|
135 |
^start + 1
|
|
136 |
] ifFalse:[
|
|
137 |
^nil
|
|
138 |
]
|
|
139 |
].
|
|
140 |
componentIdx == patternComponents size ifTrue:[
|
|
141 |
replacements ifNotNil:[
|
|
142 |
replacements
|
|
143 |
at: replacementIndex printString
|
|
144 |
put: (packageComponents asStringWith:$/ from: start to: packageComponents size)].
|
|
145 |
^start + 1.
|
|
146 |
] ifFalse:[
|
|
147 |
| next i |
|
|
148 |
next := packageComponents at: componentIdx + 1.
|
|
149 |
i := packageComponents indexOf: next startingAt: start.
|
|
150 |
i == 0 ifTrue:[^nil].
|
|
151 |
replacements ifNotNil:[
|
|
152 |
replacements
|
|
153 |
at: replacementIndex printString
|
|
154 |
put: (packageComponents asStringWith:$/ from: start to: i - 1)].
|
|
155 |
^i.
|
|
156 |
]
|
|
157 |
]
|
|
158 |
|
|
159 |
"Created: / 12-03-2011 / 21:49:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
160 |
"Modified: / 13-03-2011 / 09:32:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
161 |
!
|
|
162 |
|
|
163 |
preProcess
|
|
164 |
|
|
165 |
patternComponents := (pattern copyReplaceAll: $: with: $/) tokensBasedOn: $/.
|
|
166 |
patternComponents first isEmpty ifTrue:[patternComponents removeFirst].
|
|
167 |
patternComponents last isEmpty ifTrue:[patternComponents removeLast].
|
|
168 |
|
|
169 |
1 to: patternComponents size - 1 do:
|
|
170 |
[:i| | c |
|
|
171 |
c := patternComponents at: i.
|
|
172 |
(c = '*' and:[(patternComponents at: i+1) = '*'])
|
|
173 |
ifTrue:[self error:'Two consecutive stars may cause ambiguous match!!'].
|
|
174 |
c isEmpty
|
|
175 |
ifTrue:[self error:'Two consecutive slashes are not allowed!!'].
|
|
176 |
(c ~= '*' and:[c includes: $*])
|
|
177 |
ifTrue:[self error:'Mixed string/* matches not supported (yet)'].
|
|
178 |
]
|
|
179 |
|
|
180 |
"Created: / 12-03-2011 / 21:04:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
181 |
! !
|
|
182 |
|
|
183 |
!PackagePattern class methodsFor:'documentation'!
|
|
184 |
|
|
185 |
version
|
|
186 |
^ '$Header$'
|
|
187 |
!
|
|
188 |
|
|
189 |
version_CVS
|
|
190 |
^ '$Header$'
|
|
191 |
!
|
|
192 |
|
|
193 |
version_SVN
|
|
194 |
^ '§Id: SVN__PackagePattern.st 350 2011-07-07 18:42:56Z vranyj1 §'
|
|
195 |
! !
|