Skip to content

Commit f782602

Browse files
authored
Updated executable and code generator files
Run version19.jar as java -jar version19.jar in a directory with subdirectories output and cg. cg should contain the .cstl files, the default cstl file used by the tool should be named cg.cstl. output holds metamodels and results. iOS app output requires two subdirectories iosapp and swiftuiapp of output.
1 parent b0f35bf commit f782602

File tree

5 files changed

+431
-15
lines changed

5 files changed

+431
-15
lines changed

Ocl.swift

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,44 @@ class Ocl
626626
}
627627

628628
static func indexOf(str: String, ch: String) -> Int
629-
{ var count = 0
630-
for index in str.indices
631-
{ let c : Character = str[index]
632-
count = count + 1
633-
if (String(c) == ch)
634-
{ return count }
635-
}
636-
return 0
637-
}
629+
{ var res : Int = 0
630+
var found : Bool = false
631+
if ch.count == 0
632+
{ return 0 }
633+
634+
let sepchars = chars(str: ch)
635+
var ind : Int = 0
636+
637+
for index in str.indices
638+
{ let c : Character = str[index]
639+
640+
if found && (ind < sepchars.count)
641+
{ if (c == sepchars[ind])
642+
{ ind = ind + 1 }
643+
else
644+
{ found = false
645+
res = res + ind
646+
ind = 0
647+
}
648+
}
649+
else if found
650+
{ return res + 1 }
651+
652+
if found == false
653+
{ if c == sepchars[0]
654+
{ found = true
655+
ind = 1
656+
}
657+
}
658+
659+
if found == false
660+
{ res = res + 1 }
661+
}
662+
663+
if found
664+
{ return res + 1 }
665+
return 0
666+
}
638667

639668
static func stringSubrange(str : String, st : Int, en : Int) -> String
640669
{ var result : [Character] = [Character]()
@@ -687,7 +716,14 @@ class Ocl
687716
return result
688717
}
689718

690-
static func characters(str: String) -> [Character]
719+
static func characters(str: String) -> [String]
720+
{ var res : [String] = [String]()
721+
for ind in str.indices
722+
{ res.append(String(str[ind])) }
723+
return res
724+
}
725+
726+
static func chars(str: String) -> [Character]
691727
{ var res : [Character] = [Character]()
692728
for ind in str.indices
693729
{ res.append(str[ind]) }
@@ -696,14 +732,14 @@ class Ocl
696732

697733
static func insertAtString(s1 : String, s2 : String, ind : Int) -> String
698734
{ var result : [Character] = [Character]()
699-
let seq1 = Ocl.characters(str: s1)
700-
let seq2 = Ocl.characters(str: s2)
735+
let seq1 = Ocl.chars(str: s1)
736+
let seq2 = Ocl.chars(str: s2)
701737
result = Ocl.insertAt(s1: seq1, s2: seq2, ind: ind)
702738
return String(result)
703739
}
704740

705-
static func reverseString(s : String) -> String
706-
{ let result : [Character] = Ocl.characters(str: s)
741+
static func reverseString(str : String) -> String
742+
{ let result : [Character] = Ocl.chars(str: str)
707743
let rev = Ocl.reverse(s: result)
708744
return String(rev)
709745
}
@@ -725,6 +761,31 @@ class Ocl
725761
return result
726762
}
727763

764+
static func before(str: String, sep: String) -> String
765+
{ let ind = indexOf(str: str, ch: sep)
766+
if ind > 0
767+
{ return stringSubrange(str: str, st: 1, en: ind-1) }
768+
return str
769+
} // Single-character sep only
770+
771+
static func after(str: String, sep: String) -> String
772+
{ let revstr = reverseString(str: str)
773+
let revsep = reverseString(str: sep)
774+
let ind = indexOf(str: revstr, ch: revsep)
775+
if ind > 0
776+
{ let res = stringSubrange(str: revstr, st: 1, en: ind-1)
777+
return reverseString(str: res)
778+
}
779+
return ""
780+
} // Single-character sep only
781+
782+
static func matches(str: String, pattern: String) -> Bool
783+
{ let rge = NSRange(location: 0, length: str.utf16.count)
784+
var regexp = try! NSRegularExpression(pattern: pattern)
785+
let pred = regexp.firstMatch(in: str, options: [], range: rge)
786+
return pred != nil
787+
}
788+
728789
/* Only for Swift 5+
729790
static func before(str: String, sep: String) -> String
730791
{ if let ind = str.firstIndex(of: sep)

cgJava8.cstl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ _1->hasPrefix(_2) |-->_1.startsWith(_2)
227227
_1->hasSuffix(_2) |-->_1.endsWith(_2)
228228
_1->after(_2) |-->Ocl.after(_1,_2))
229229
_1->before(_2) |-->Ocl.before(_1,_2)
230+
_1->matches(_2) |-->java.util.regex.Pattern.matches(_2,_1)
231+
230232

231233

232234

0 commit comments

Comments
 (0)