ResourcePack.st
changeset 8949 d3a4a0c15644
parent 8914 a87a429d0a2f
child 8959 1ae921a9bff2
--- a/ResourcePack.st	Thu Dec 19 15:52:01 2019 +0100
+++ b/ResourcePack.st	Thu Dec 19 19:41:37 2019 +0100
@@ -1071,22 +1071,9 @@
           or aKey is '(...)', then lookup ... wrap () around the result.
           or aKey is '[...]', then lookup ... wrap [] around the result.
           or aKey is '{...}', then lookup ... wrap {} around the result.
-          or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result.
-          or aKey starts with a '*', then lookup aKey without '*' and prepend '*' to the result.
-          or aKey starts with a '<', then lookup aKey without '<' and prepend '<' to the result.
-          or aKey starts with a '«', then lookup aKey without '«' and prepend '«' to the result.
+          or aKey starts with any of '\*<« ', then lookup aKey without the prefix and prepend prefix to the result.
           or aKey ends with ''%1'' , then lookup aKey without ''%1'' and append ''%1'' to the result.
-          or aKey ends with a '>', then lookup aKey without '>' and append '>' to the result.
-          or aKey ends with a '»', then lookup aKey without '»' and append '»' to the result.
-          or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result.
-          or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result.
-          or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result.
-          or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result.
-          or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result.
-          or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result.
-          or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result.
-          or aKey ends with a '*', then lookup aKey without '*' and append '*' to the result.
-          or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result.
+          or aKey ends with any of '>»\:=.,?!!* ', then lookup aKey without the suffix and append suffix to the result.
           or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result.
           or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result.
           or aKey includes '&', then lookup aKey without '&'.
@@ -1098,7 +1085,7 @@
         'search...'
     "
 
-    |val alternativeKey usedKey idx first last|
+    |val alternativeKey usedKey idx first last cutOff|
 
     val := super at:aKey ifAbsent:nil.
     val notNil ifTrue:[
@@ -1183,21 +1170,29 @@
         
         (';*:=.?!!,-><\/«»' includes:last) ifTrue:[
             aKey size >= 2 ifTrue:[
-                usedKey := aKey copyButLast:1.
-
-                val := self localAt:usedKey.        "/ recursion
-                val notNil ifTrue:[^ val copyWith:last].
+                idx := aKey findLast:[:ch | (';*:=.?!!,-><\/«»' includes:ch) not].
+                idx ~~ 0 ifTrue:[
+                    cutOff := aKey copyFrom:idx+1.
+                    usedKey := aKey copyTo:idx.
+                    val := self localAt:usedKey.        "/ recursion
+                    val notNil ifTrue:[^ val , cutOff].
+                    ^ nil
+                ].
             ].
         ].
         (';*:=.?!!-><\/«»' includes:first) ifTrue:[
             aKey size >= 2 ifTrue:[
-                usedKey := aKey copyButFirst:1.
-
-                val := self localAt:usedKey.        "/ recursion
-                val notNil ifTrue:[^ first asString , val].
+                idx := aKey findFirst:[:ch | (';*:=.?!!,-><\/«»' includes:ch) not].
+                idx ~~ 0 ifTrue:[
+                    cutOff := aKey copyTo:idx-1.
+                    usedKey := aKey copyFrom:idx.
+                    val := self localAt:usedKey.        "/ recursion
+                    val notNil ifTrue:[^ cutOff , val].
+                    ^ nil
+                ].
             ].
         ].
-
+        "/ try without '&'-char (but not if doubled)
         (idx := aKey indexOf:$&) ~~ 0 ifTrue:[
             (aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[
                 usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1).
@@ -1208,6 +1203,18 @@
     ].
     ^ nil.
 
+    "
+     |pack|
+
+     pack := ResourcePack new.
+     pack at:'foo' put:'bar'.
+     pack at:'foo'.     
+     pack at:'foo-----'. 
+     pack at:'-----foo'.  
+     pack at:'-----foo-----'.  
+     pack at:'-----...-----'.    
+    "         
+
     "Created: / 18-09-2006 / 17:33:27 / cg"
     "Modified: / 05-08-2010 / 16:52:32 / sr"
     "Modified: / 27-11-2017 / 15:33:48 / cg"