From 0c657a4820003191b5a7bced937c02f92d2852a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Doser?= Date: Fri, 8 Dec 2006 13:26:24 +0000 Subject: [PATCH] git-svn-id: https://projects.brucker.ch/su4sml/svn/infsec-import/trunk/src/su4sml@5700 3260e6d1-4efc-4170-b0a7-36055960796d --- src/codegen/stringHandling.sml | 59 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/codegen/stringHandling.sml b/src/codegen/stringHandling.sml index e4e4424..9d0cadc 100644 --- a/src/codegen/stringHandling.sml +++ b/src/codegen/stringHandling.sml @@ -1,9 +1,9 @@ structure StringHandling = struct -open StateMachineTypes -(* returns the capitalized string *) -(* string -> string *) +open library + +(** returns the capitalized string. *) fun toUpper(S:string) = String.implode (List.map Char.toUpper (String.explode S)) (*reassemble given string list by concatenating every time the string character to each element and return the whole as a string *) @@ -12,25 +12,38 @@ fun reassemble(S: string list,c : string) = String.concat (List.map (fn x => x^c fun concatBefore(S: string list, c: string) = String.concat (List.map (fn x =>c^x) S) (* Pair list * string -> string *) -fun replace_vars_in_String(L:Pair list,Str) = let val LINES = String.tokens (fn x => x = #"\n") Str - fun isVariable(S) = (List.length (List.filter (fn x => x = #"$") (String.explode S))) = 2 (*string->bool*) - fun isEqual(s1:string,s2:string) = (s1<=s2) andalso (s1>=s2)(*string*string -> bool*) - fun filterOut(VarName) = List.filter (fn X => isEqual(VarN(X),VarName)) L(*string -> Pair list*) - fun VarIt(x) = String.tokens (fn x => x = #"$") x - fun process([],R) = R - | process(h::t,R) = let val Filtered = filterOut(h) - in - if (List.length Filtered) > 0 then process(t,R@[VarV(hd Filtered)]) - else process(t,R@[h]) - end - fun replace(Str) = let val TABBED = String.tokens (fn x => x = #"\t") Str - val VARRED = List.map VarIt TABBED - val P = List.map (fn X => process(X,[])) VARRED - in - String.concatWith "\t" (List.map (fn X => (String.concatWith "" X)) P) - end - in - String.concatWith "\n" (List.map replace LINES) - end +fun replace_vars_in_String(L:(string*string) list,Str) = + let val LINES = String.tokens (fn x => x = #"\n") Str + fun isVariable(S) = (List.length (List.filter (fn x => x = #"$") (String.explode S))) = 2 (*string->bool*) + fun isEqual(s1:string,s2:string) = (s1<=s2) andalso (s1>=s2)(*string*string -> bool*) + fun filterOut(VarName) = List.filter (fn X => isEqual(fst(X),VarName)) L(*string -> Pair list*) + fun VarIt(x) = String.tokens (fn x => x = #"$") x + fun process([],R) = R + | process(h::t,R) = let val Filtered = filterOut(h) + in + if (List.length Filtered) > 0 then process(t,R@[snd(hd Filtered)]) + else process(t,R@[h]) + end + fun replace(Str) = let val TABBED = String.tokens (fn x => x = #"\t") Str + val VARRED = List.map VarIt TABBED + val P = List.map (fn X => process(X,[])) VARRED + in + String.concatWith "\t" (List.map (fn X => (String.concatWith "" X)) P) + end + in + String.concatWith "\n" (List.map replace LINES) + end + + +fun startWithSmallLetter s = let val sl = String.explode s + in + String.implode ((Char.toLower (hd sl))::(tl sl)) + end + +fun startWithCapital s = let val sl = String.explode s + in + String.implode ((Char.toUpper (hd sl))::(tl sl)) + end + end