Skip to content

Commit

Permalink
Fix regex usage
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14954 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 26, 2013
1 parent 78af88c commit 77f9513
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ protected
String matches[4];
algorithm
(i,matches) := regex(path, "^(.*/testsuite/)?(.*/build/)?(.*)",4);
fixed := matches[i+1];
fixed := matches[i];
end testsuiteFriendlyName;

function readFileNoNumeric
Expand Down Expand Up @@ -1934,14 +1934,13 @@ protected
algorithm
isUri := regexBool(uri, "^[A-Za-z]*://");
if isUri then
(numMatches,matches) := regex(uri,"^([A-Za-z]*://)?([^/]*)(.*)$",4);
schema := matches[2];
isModelicaUri := regexBool(schema, "^modelica://", caseInsensitive=true);
(numMatches,matches) := regex(uri,"^[A-Za-z]*://?([^/]*)(.*)$",4);
isModelicaUri := regexBool(uri, "^modelica://", caseInsensitive=true);
isFileUriAbsolute := regexBool(uri, "^file:///", caseInsensitive=true);
isFileUri := regexBool(schema, "^file://", caseInsensitive=true);
isFileUri := regexBool(uri, "^file://", caseInsensitive=true);
if isModelicaUri then
libraries := getLoadedLibraries();
path := matches[3];
path := matches[2];
while path <> "" loop
(numMatches,matches2) := regex(path, "^([A-Za-z_][A-Za-z0-9_]*)?[.]?(.*)?$",3);
path := matches2[3];
Expand All @@ -1966,7 +1965,7 @@ algorithm
assert(isMatch,"Could not resolve URI: " + uri);
end if;
end while;
filename := if isMatch then realpath(filename + "/" + matches[4]) else filename;
filename := if isMatch then realpath(filename + "/" + matches[3]) else filename;
elseif isFileUriAbsolute then
(,matches) := regex(uri,"file://(/.*)?",2);
filename := matches[2];
Expand All @@ -1976,7 +1975,7 @@ algorithm
assert(false, str);
elseif not (isModelicaUri or isFileUri) then
/* Not using else because OpenModelica handling of assertions at runtime is not very good */
str := "Unknown URI schema: " + schema;
str := "Unknown URI schema: " + uri;
print(str + "\n");
assert(false, str);
else
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/util/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extern int OpenModelica_regexImpl(const char* str, const char* re, const int max
nmatch += res == 0 ? 1 : 0;
else if (maxn) {
dup = strdup(str);
for (i=maxn-1; i>=0; i--) {
for (i=0; i<maxn; i++) {
if (!res && matches[i].rm_so != -1) {
memcpy(dup, str + matches[i].rm_so, matches[i].rm_eo - matches[i].rm_so);
dup[matches[i].rm_eo - matches[i].rm_so] = '\0';
Expand Down

0 comments on commit 77f9513

Please sign in to comment.