Permalink
Browse files

* Modified TextManager.Match to only make partial matches if asterisk…

…s are explicitly added to the beginning and/or end of the pattern.
  • Loading branch information...
1 parent 055a375 commit f27edd8540342e6d776eaae134d24988c1887697 @YotaXP YotaXP committed May 21, 2012
Showing with 19 additions and 9 deletions.
  1. +19 −9 code/controllers/managers/textman.dm
@@ -260,27 +260,37 @@ TextManager
// Simple string matching procedure.
// Crashed, C*a*h*d will match.
// Crashed, Crah*d will not (missing s).
+ // Crashed, Crash* will match.
+ // Crashed, Crash will not (missing ed).
Match(string, pattern)
+ if(!string || !pattern) return 0
+
var parts[] = list()
var find = findtext(pattern, "*")
+ var startWild = find == 1
+ var endWild = text2ascii(pattern, length(pattern)) == 42 // '*'
while(find)
- var part = copytext(pattern, 1, find)
- parts += part
+ if(find > 1) parts += copytext(pattern, 1, find)
pattern = copytext(pattern, find + 1)
find = findtext(pattern, "*")
- parts += pattern
+ if(pattern) parts += pattern
+
+ if(!parts.len) return 1 // "*" pattern
+
+ find = findtext(string, parts[1])
+ if(!find || (!startWild && find != 1)) return 0
- if(!length(parts)) return 0
+ find += length(parts[1])
+ parts.Cut(1, 2)
- find = 1
for(var/part in parts)
- find = findtext(string, part, find) + length(part)
- if(find == length(part))
- return 0
+ find = findtext(string, part, find)
+ if(find) find += length(part)
+ else return 0
- return 1
+ return endWild || find == length(string)+1
fadetext(var/text, var/list/colors)
if(!colors) return text

0 comments on commit f27edd8

Please sign in to comment.