author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 18 Oct 2012 16:26:51 +0200 | |
changeset 1128 | 30a62d7a8050 |
parent 888 | 132efbbc8803 |
child 1171 | 3d1dc13fecf8 |
permissions | -rw-r--r-- |
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 |
||
888
132efbbc8803
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
651
diff
changeset
|
77 |
!PackagePattern class methodsFor:'others'! |
132efbbc8803
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
651
diff
changeset
|
78 |
|
132efbbc8803
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
651
diff
changeset
|
79 |
version_CVS |
132efbbc8803
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
651
diff
changeset
|
80 |
^ '$Header$' |
132efbbc8803
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
651
diff
changeset
|
81 |
! ! |
132efbbc8803
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
651
diff
changeset
|
82 |
|
651 | 83 |
!PackagePattern methodsFor:'initialization'! |
84 |
||
85 |
setPattern:something |
|
86 |
pattern := something. |
|
87 |
self preProcess |
|
88 |
||
89 |
"Created: / 12-03-2011 / 20:58:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
90 |
! ! |
|
91 |
||
92 |
!PackagePattern methodsFor:'matching'! |
|
93 |
||
94 |
match: package into: replacements |
|
95 |
||
96 |
| packageComponents start replacementIndex replacementSize | |
|
97 |
||
98 |
"Ugly code warning. Q&D hack" |
|
99 |
||
100 |
packageComponents := (package copyReplaceAll: $: with: $/) tokensBasedOn: $/. |
|
101 |
start := 1. |
|
102 |
replacementIndex := 1. |
|
103 |
replacementSize := replacements size. |
|
104 |
1 to: patternComponents size do: |
|
105 |
[:i| |
|
106 |
start := self matchAt: i into: replacements index: replacementIndex in: packageComponents from: start. |
|
107 |
replacementSize ~= replacements size ifTrue: |
|
108 |
[replacementIndex := replacementIndex + 1. |
|
109 |
replacementSize := replacements size]. |
|
110 |
start ifNil:[^false]]. |
|
111 |
^true. |
|
112 |
||
113 |
"Created: / 12-03-2011 / 21:21:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
114 |
! |
|
115 |
||
116 |
matches: package |
|
117 |
||
118 |
^self match: package into: nil. |
|
119 |
||
120 |
"Created: / 12-03-2011 / 21:20:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
121 |
! ! |
|
122 |
||
1128 | 123 |
!PackagePattern methodsFor:'printing & storing'! |
124 |
||
125 |
printOn:aStream |
|
126 |
"append a printed representation if the receiver to the argument, aStream" |
|
127 |
||
128 |
pattern printOn:aStream. |
|
129 |
||
130 |
"Modified: / 18-10-2012 / 16:02:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
131 |
! ! |
|
132 |
||
651 | 133 |
!PackagePattern methodsFor:'private'! |
134 |
||
135 |
matchAt: componentIdx into: replacements index: replacementIndex in: packageComponents from: start |
|
136 |
||
137 |
| component | |
|
138 |
component := patternComponents at: componentIdx. |
|
139 |
component ~= '*' ifTrue:[ |
|
140 |
start > packageComponents size ifTrue:[^nil]. |
|
141 |
(packageComponents at: start) = component |
|
142 |
ifTrue:[^start + 1] |
|
143 |
ifFalse:[^nil] |
|
144 |
] ifFalse:[ |
|
145 |
start > packageComponents size ifTrue:[ |
|
146 |
componentIdx == patternComponents size ifTrue:[ |
|
147 |
replacements ifNotNil:[ |
|
148 |
replacements |
|
149 |
at: replacementIndex printString |
|
150 |
put: '']. |
|
151 |
^start + 1 |
|
152 |
] ifFalse:[ |
|
153 |
^nil |
|
154 |
] |
|
155 |
]. |
|
156 |
componentIdx == patternComponents size ifTrue:[ |
|
157 |
replacements ifNotNil:[ |
|
158 |
replacements |
|
159 |
at: replacementIndex printString |
|
160 |
put: (packageComponents asStringWith:$/ from: start to: packageComponents size)]. |
|
161 |
^start + 1. |
|
162 |
] ifFalse:[ |
|
163 |
| next i | |
|
164 |
next := packageComponents at: componentIdx + 1. |
|
165 |
i := packageComponents indexOf: next startingAt: start. |
|
166 |
i == 0 ifTrue:[^nil]. |
|
167 |
replacements ifNotNil:[ |
|
168 |
replacements |
|
169 |
at: replacementIndex printString |
|
170 |
put: (packageComponents asStringWith:$/ from: start to: i - 1)]. |
|
171 |
^i. |
|
172 |
] |
|
173 |
] |
|
174 |
||
175 |
"Created: / 12-03-2011 / 21:49:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
176 |
"Modified: / 13-03-2011 / 09:32:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
177 |
! |
|
178 |
||
179 |
preProcess |
|
180 |
||
181 |
patternComponents := (pattern copyReplaceAll: $: with: $/) tokensBasedOn: $/. |
|
182 |
patternComponents first isEmpty ifTrue:[patternComponents removeFirst]. |
|
183 |
patternComponents last isEmpty ifTrue:[patternComponents removeLast]. |
|
184 |
||
185 |
1 to: patternComponents size - 1 do: |
|
186 |
[:i| | c | |
|
187 |
c := patternComponents at: i. |
|
188 |
(c = '*' and:[(patternComponents at: i+1) = '*']) |
|
189 |
ifTrue:[self error:'Two consecutive stars may cause ambiguous match!!']. |
|
190 |
c isEmpty |
|
191 |
ifTrue:[self error:'Two consecutive slashes are not allowed!!']. |
|
192 |
(c ~= '*' and:[c includes: $*]) |
|
193 |
ifTrue:[self error:'Mixed string/* matches not supported (yet)']. |
|
194 |
] |
|
195 |
||
196 |
"Created: / 12-03-2011 / 21:04:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
197 |
! ! |
|
198 |
||
199 |
!PackagePattern class methodsFor:'documentation'! |
|
200 |
||
201 |
version |
|
202 |
^ '$Header$' |
|
203 |
! |
|
204 |
||
205 |
version_SVN |
|
888
132efbbc8803
checkin to get version methods correct
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
651
diff
changeset
|
206 |
^ '§Id: SVN__PackagePattern.st 362 2011-08-08 13:07:42Z vranyj1 §' |
651 | 207 |
! ! |