diff --git a/OMCompiler/Compiler/BackEnd/BackendVariable.mo b/OMCompiler/Compiler/BackEnd/BackendVariable.mo index 70005964b24..be3f0993a35 100644 --- a/OMCompiler/Compiler/BackEnd/BackendVariable.mo +++ b/OMCompiler/Compiler/BackEnd/BackendVariable.mo @@ -63,6 +63,7 @@ import List; import MetaModelica.Dangerous; import Mutable; import SCodeUtil; +import StringUtil; import System; import Types; import Util; @@ -1441,13 +1442,11 @@ public function isRESVar input BackendDAE.Var inVar; output Boolean outBoolean; algorithm - outBoolean := match (inVar.varName) + outBoolean := match inVar.varName local String s; - case(DAE.CREF_IDENT(ident=s)) - then (stringLength(s) > 3 and substring(s, 1, 4) == "$res"); - case(DAE.CREF_QUAL(ident=s)) - then (stringLength(s) > 3 and substring(s, 1, 4) == "$res"); + case DAE.CREF_IDENT(ident=s) then StringUtil.startsWith(s, "$res"); + case DAE.CREF_QUAL(ident=s) then StringUtil.startsWith(s, "$res"); else false; end match; end isRESVar; @@ -4445,9 +4444,7 @@ end calcAliasKey; public function selfGeneratedVar input DAE.ComponentRef inCref; - output Boolean b; -algorithm - b := substring(ComponentReference.crefStr(inCref), 1, 1) == "$"; + output Boolean b = StringUtil.startsWith(ComponentReference.crefStr(inCref), "$"); end selfGeneratedVar; public function varStateSelectPrioAlias "Helper function to calculateVarPriorities. diff --git a/OMCompiler/Compiler/BackEnd/CommonSubExpression.mo b/OMCompiler/Compiler/BackEnd/CommonSubExpression.mo index 0468b18ebd1..efbda5153b6 100644 --- a/OMCompiler/Compiler/BackEnd/CommonSubExpression.mo +++ b/OMCompiler/Compiler/BackEnd/CommonSubExpression.mo @@ -64,6 +64,7 @@ import HashTableExpToIndex; import HpcOmTaskGraph; import List; import ResolveLoops; +import StringUtil; import Types; uniontype CSE_Equation @@ -1645,32 +1646,25 @@ public function isCSECref "Returns true if the cref is prefixed with '$cse'" input DAE.ComponentRef cr; output Boolean b; -protected - String s; algorithm - b := matchcontinue(cr) - case(DAE.CREF_IDENT(ident=s)) - then (stringLength(s) > 3 and substring(s, 1, 4) == "$cse"); - case(DAE.CREF_QUAL(ident=s)) - then (stringLength(s) > 3 and substring(s, 1, 4) == "$cse"); - end matchcontinue; + b := match cr + local + String s; + case DAE.CREF_IDENT(ident=s) then StringUtil.startsWith(s, "$cse"); + case DAE.CREF_QUAL(ident=s) then StringUtil.startsWith(s, "$cse"); + else false; + end match; end isCSECref; public function isCSEExp "Returns true if the exp is prefixed with '$cse'" input DAE.Exp inExp; output Boolean b; -protected - DAE.ComponentRef cr; - String s; algorithm - try - cr := Expression.expCref(inExp); - DAE.CREF_IDENT(ident=s) := cr; - b := substring(s, 1, 4) == "$cse"; - else - b := false; - end try; + b := match inExp + case DAE.CREF() then isCSECref(inExp.componentRef); + else false; + end match; end isCSEExp; public function cseBinary "authors: Jan Hagemann and Lennart Ochel (FH Bielefeld, Germany) diff --git a/OMCompiler/Compiler/BackEnd/Differentiate.mo b/OMCompiler/Compiler/BackEnd/Differentiate.mo index 8713219f153..53f1d782db7 100644 --- a/OMCompiler/Compiler/BackEnd/Differentiate.mo +++ b/OMCompiler/Compiler/BackEnd/Differentiate.mo @@ -73,6 +73,7 @@ protected import Flags; protected import Inline; protected import List; protected import SCode; +protected import StringUtil; protected import Util; protected import SymbolicJacobian.DAE_CJ; @@ -1328,11 +1329,11 @@ public function isSeedCref input DAE.ComponentRef cr; output Boolean b; algorithm - b := matchcontinue(cr) - case(DAE.CREF_IDENT()) then (substring(cr.ident, 1, 4) == "Seed"); - case(DAE.CREF_QUAL()) then isSeedCref(cr.componentRef); + b := match cr + case DAE.CREF_IDENT() then StringUtil.startsWith(cr.ident, "Seed"); + case DAE.CREF_QUAL() then StringUtil.startsWith(cr.ident, "Seed"); else false; - end matchcontinue; + end match; end isSeedCref; protected function differentiateCalls diff --git a/OMCompiler/Compiler/BackEnd/Initialization.mo b/OMCompiler/Compiler/BackEnd/Initialization.mo index 630f06cf40c..81b2da90ccd 100644 --- a/OMCompiler/Compiler/BackEnd/Initialization.mo +++ b/OMCompiler/Compiler/BackEnd/Initialization.mo @@ -42,6 +42,7 @@ import BackendDAE; import BackendDAEFunc; import DAE; import HashSet; +import StringUtil; import Util; protected @@ -2423,7 +2424,7 @@ algorithm if isFixed then // Special case for initial state selection - if Util.stringStartsWith("$STATESET",ComponentReference.crefFirstIdent(cr)) and Flags.getConfigBool(Flags.INITIAL_STATE_SELECTION) then + if StringUtil.startsWith(ComponentReference.crefFirstIdent(cr), "$STATESET") and Flags.getConfigBool(Flags.INITIAL_STATE_SELECTION) then stateSetSplit = Util.stringSplitAtChar(ComponentReference.crefFirstIdent(cr),"."); stateSetIdxString::stateSetSplit = stateSetSplit; stateSetIdxString = substring(stateSetIdxString,10,stringLength(stateSetIdxString)); diff --git a/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo b/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo index 8e060eb5a9e..c3e41e64d01 100644 --- a/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo +++ b/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo @@ -73,6 +73,7 @@ import Graph; import HashSet; import IndexReduction; import List; +import StringUtil; import System; import UnorderedMap; import Util; @@ -4435,9 +4436,9 @@ algorithm local DAE.ComponentRef cr; - case DAE.CREF_IDENT() guard(stringLength(cref.ident) > 4 and substring(cref.ident, 1, 5) == "$pDER") then (cref, true); + case DAE.CREF_IDENT() guard(StringUtil.startsWith(cref.ident, "$pDER")) then (cref, true); - case DAE.CREF_QUAL() guard(stringLength(cref.ident) > 4 and substring(cref.ident, 1, 5) == "$pDER") then (cref, true); + case DAE.CREF_QUAL() guard(StringUtil.startsWith(cref.ident, "$pDER")) then (cref, true); case DAE.CREF_QUAL() algorithm (cr, strip) := stripPartialDerWork(cref.componentRef); diff --git a/OMCompiler/Compiler/BackEnd/SynchronousFeatures.mo b/OMCompiler/Compiler/BackEnd/SynchronousFeatures.mo index 97d428e3ecb..da3e61244ea 100644 --- a/OMCompiler/Compiler/BackEnd/SynchronousFeatures.mo +++ b/OMCompiler/Compiler/BackEnd/SynchronousFeatures.mo @@ -59,6 +59,7 @@ import Flags; import HashTable; import List; import MMath; +import StringUtil; import Types; import Util; import MetaModelica.Dangerous.listReverseInPlace; @@ -252,7 +253,7 @@ algorithm subPartition := shared.partitionsInfo.subPartitions[idx]; solverMethod := BackendDump.optionString(getSubClockSolverOpt(subPartition.clock)); // check solverMethod - if stringLength(solverMethod) > 7 and substring(solverMethod, 1, 8) == "Explicit" then + if StringUtil.startsWith(solverMethod, "Explicit") then if solverMethod <> "ExplicitEuler" then Error.addMessage(Error.CLOCK_SOLVERMETHOD, {"ExplicitEuler", solverMethod}); solverMethod := "ExplicitEuler"; diff --git a/OMCompiler/Compiler/FrontEnd/ComponentReference.mo b/OMCompiler/Compiler/FrontEnd/ComponentReference.mo index bed61c4cfd9..4faa1d59566 100644 --- a/OMCompiler/Compiler/FrontEnd/ComponentReference.mo +++ b/OMCompiler/Compiler/FrontEnd/ComponentReference.mo @@ -55,6 +55,7 @@ protected import Flags; protected import List; protected import MetaModelica.Dangerous; protected import Print; +protected import StringUtil; protected import System; protected import Types; protected import Util; @@ -1207,10 +1208,8 @@ algorithm b := match(cr) case(DAE.CREF_QUAL(ident=DAE.derivativeNamePrefix)) then false; // allow exception for derivate vars case(DAE.CREF_QUAL(ident=DAE.previousNamePrefix)) then false; // allow exception for Clk-previous vars - case(DAE.CREF_IDENT(ident=s)) - then (substring(s, 1, 1) == "$"); - case(DAE.CREF_QUAL(ident=s)) - then (substring(s, 1, 1) == "$"); + case(DAE.CREF_IDENT(ident=s)) then StringUtil.startsWith(s, "$"); + case(DAE.CREF_QUAL(ident=s)) then StringUtil.startsWith(s, "$"); else false; end match; end isInternalCref; diff --git a/OMCompiler/Compiler/FrontEnd/Inst.mo b/OMCompiler/Compiler/FrontEnd/Inst.mo index 41260323cc0..d7a64f8a50c 100644 --- a/OMCompiler/Compiler/FrontEnd/Inst.mo +++ b/OMCompiler/Compiler/FrontEnd/Inst.mo @@ -148,7 +148,6 @@ import Mutable; import PrefixUtil; import SCodeUtil; import SCodeInstUtil; -import StringUtil; import Static; import Types; import UnitParserExt; @@ -5556,9 +5555,7 @@ protected function generateCachePath protected String name; algorithm - name := StringUtil.stringAppend9(InstTypes.callingScopeStr(callScope), "$", - SCodeDump.restrString(SCodeUtil.getClassRestriction(cls)), "$", - generatePrefixStr(prefix), "$"); + name := InstTypes.callingScopeStr(callScope) + "$" + SCodeDump.restrString(SCodeUtil.getClassRestriction(cls)) + "$" + generatePrefixStr(prefix) + "$"; cachePath := AbsynUtil.joinPaths(Absyn.IDENT(name), FGraph.getGraphName(env)); end generateCachePath; diff --git a/OMCompiler/Compiler/FrontEnd/Mod.mo b/OMCompiler/Compiler/FrontEnd/Mod.mo index 95fa80eb28b..53213005ea5 100644 --- a/OMCompiler/Compiler/FrontEnd/Mod.mo +++ b/OMCompiler/Compiler/FrontEnd/Mod.mo @@ -2456,7 +2456,7 @@ algorithm len1 = stringLength(i); len2 = stringLength(idx); // either one of them is a substring of the other - true = boolOr(0 == System.strncmp(i, idx, len1), 0 == System.strncmp(idx, i, len2)); + true = (0 == System.strncmp(i, idx, intMin(len1, len2))); then true; else false; end matchcontinue; diff --git a/OMCompiler/Compiler/NBackEnd/Classes/NBVariable.mo b/OMCompiler/Compiler/NBackEnd/Classes/NBVariable.mo index fc31a5f59ca..368362dd773 100644 --- a/OMCompiler/Compiler/NBackEnd/Classes/NBVariable.mo +++ b/OMCompiler/Compiler/NBackEnd/Classes/NBVariable.mo @@ -562,7 +562,7 @@ public function isFunctionAlias extends checkVar; algorithm - b := Util.stringStartsWith(FUNCTION_STR, ComponentRef.firstName(getVarName(var_ptr))); + b := StringUtil.startsWith(ComponentRef.firstName(getVarName(var_ptr)), FUNCTION_STR); end isFunctionAlias; function createTimeVar diff --git a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBAdjacency.mo b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBAdjacency.mo index 108bfc5e736..3b3ac37b4ed 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBAdjacency.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBAdjacency.mo @@ -59,6 +59,7 @@ protected import BackendUtil = NBBackendUtil; import BuiltinSystem = System; import Slice = NBSlice; + import StringUtil; // SetBased Graph imports import SBGraph.BipartiteIncidenceList; diff --git a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBInitialization.mo b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBInitialization.mo index d3302e1f16e..ef0b81fae31 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBInitialization.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBInitialization.mo @@ -73,6 +73,7 @@ protected import ClockIndexes; import DoubleEnded; import Slice = NBSlice; + import StringUtil; public function main extends Module.wrapper; diff --git a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBMatching.mo b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBMatching.mo index db6c1b91998..4516153bedf 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBMatching.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBMatching.mo @@ -63,6 +63,7 @@ protected import BackendUtil = NBBackendUtil; import Slice = NBSlice; import NBSlice.IntLst; + import StringUtil; public // ======================================= // MATCHING diff --git a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBResolveSingularities.mo b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBResolveSingularities.mo index 5d97a6a2ca7..899d58c93f8 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBResolveSingularities.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBResolveSingularities.mo @@ -56,6 +56,7 @@ protected // util imports import BackendUtil = NBBackendUtil; import Slice = NBSlice; + import StringUtil; import UnorderedSet; public diff --git a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBBindings.mo b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBBindings.mo index 8bf0586bf0c..b973d051994 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBBindings.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBBindings.mo @@ -43,6 +43,9 @@ protected import BVariable = NBVariable; import NBVariable.{VariablePointers, VarData}; + // Util + import StringUtil; + public function main extends Module.wrapper; algorithm diff --git a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo index 462c78c5c6e..a00ab7a2b5c 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo @@ -60,6 +60,10 @@ protected import Differentiate = NBDifferentiate; import NBEquation.{Equation, EquationPointers, EqData, WhenEquationBody, WhenStatement}; import NBVariable.{VariablePointers, VarData}; + + // Util + import StringUtil; + // ========================================================================= // MAIN ROUTINE, PLEASE DO NOT CHANGE // ========================================================================= diff --git a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBFunctionAlias.mo b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBFunctionAlias.mo index 354bb810a82..92b7645b1cd 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBFunctionAlias.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBFunctionAlias.mo @@ -61,6 +61,7 @@ protected import NBVariable.{VariablePointers, VarData}; // Util imports + import StringUtil; import UnorderedMap; public function main diff --git a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBInline.mo b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBInline.mo index 6c19f6e5172..4272e340005 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBInline.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBInline.mo @@ -61,6 +61,9 @@ protected import Replacements = NBReplacements; import NBVariable.{VariablePointers, VarData}; + // Util + import StringUtil; + // ========================================================================= // MAIN ROUTINE, PLEASE DO NOT CHANGE // ========================================================================= diff --git a/OMCompiler/Compiler/NBackEnd/Modules/NBModule.mo b/OMCompiler/Compiler/NBackEnd/Modules/NBModule.mo index 9297518db15..93d75fb1413 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/NBModule.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/NBModule.mo @@ -81,6 +81,7 @@ protected // Util imports import BuiltinSystem = System; + import StringUtil; public partial function wrapper diff --git a/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo b/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo index 55ea2d893eb..456ae1aa72d 100644 --- a/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo +++ b/OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo @@ -67,6 +67,9 @@ protected import StrongComponent = NBStrongComponent; import NBVariable.{VarData, VariablePointers}; + // Util + import StringUtil; + public // ========================================================================= // COMPONENT REFERENCE REPLACEMENT diff --git a/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo b/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo index 8695ae55428..f3bd0153c38 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo @@ -47,6 +47,7 @@ protected import Prefixes = NFPrefixes; import MetaModelica.Dangerous.*; import JSON; + import StringUtil; import Variable = NFVariable; import ComponentRef = NFComponentRef; @@ -1093,7 +1094,7 @@ public function backendCref "returns true if the cref was generated by the backend (starts with $)" input ComponentRef cref; - output Boolean b = substring(firstName(cref), 1, 1) == "$"; + output Boolean b = StringUtil.startsWith(firstName(cref), "$"); end backendCref; function toAbsyn diff --git a/OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo b/OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo index 380557cd3bf..e9a4453624c 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo @@ -51,6 +51,7 @@ protected import NFComponentRef.ComponentRef; import DAE.ElementSource; import MetaModelica.Dangerous.listReverseInPlace; + import StringUtil; import Util; import Prefixes = NFPrefixes; import NFPrefixes.Visibility; @@ -910,7 +911,7 @@ public case "unassignedMessage" then false; case "Protection" then false; case "Authorization" then false; - else not Util.stringStartsWith("__", mod.ident); + else not StringUtil.startsWith(mod.ident, "__"); end match; end isAllowedAnnotation; diff --git a/OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo b/OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo index 4b882b335ce..98b354bb3a3 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo @@ -65,6 +65,7 @@ import Sections = NFSections; import NFOCConnectionGraph; import Prefixes = NFPrefixes; import RangeIterator = NFRangeIterator; +import StringUtil; import Subscript = NFSubscript; import Type = NFType; import Util; @@ -1277,7 +1278,6 @@ function addIterator_traverse input list subscripts; protected String restString, prefixString = ComponentRef.toString(Prefix.prefix(prefix)); - Integer prefixLength = stringLength(prefixString); algorithm exp := match exp local @@ -1285,7 +1285,7 @@ algorithm case Expression.CREF(cref = ComponentRef.CREF(restCref = restCref)) algorithm restString := ComponentRef.toString(restCref); - if prefixLength <= stringLength(restString) and prefixString == substring(restString, 1, prefixLength) then + if StringUtil.startsWith(restString, prefixString) then exp.cref := ComponentRef.mergeSubscripts(subscripts, exp.cref, applyToScope = true); end if; then diff --git a/OMCompiler/Compiler/NFFrontEnd/NFFunction.mo b/OMCompiler/Compiler/NFFrontEnd/NFFunction.mo index 148c258b442..6408229a7b5 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFFunction.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFFunction.mo @@ -54,6 +54,7 @@ import InstUtil; import Class = NFClass; import Component = NFComponent; import Attributes = NFAttributes; +import StringUtil; import Typing = NFTyping; import TypeCheck = NFTypeCheck; import Util; @@ -2390,10 +2391,8 @@ protected name := InstNode.name(component); // Remove $in_ for OM input output arguments. - if stringGet(name, 1) == 36 /*$*/ then - if stringLength(name) > 4 and substring(name, 1, 4) == "$in_" then - name := substring(name, 5, stringLength(name)); - end if; + if StringUtil.startsWith(name, "$in_") then + name := substring(name, 5, stringLength(name)); end if; slot := SLOT(component, SlotType.GENERIC, default, NONE(), index, SlotEvalStatus.NOT_EVALUATED); diff --git a/OMCompiler/Compiler/NFFrontEnd/NFType.mo b/OMCompiler/Compiler/NFFrontEnd/NFType.mo index 8074c5da0cd..5c9d58ed310 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFType.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFType.mo @@ -36,6 +36,7 @@ protected import List; import Class = NFClass; import IOStream; + import StringUtil; import Util; import NFClassTree.ClassTree; @@ -904,7 +905,7 @@ public case Type.FUNCTION() then Function.typeString(ty.fn); case Type.METABOXED() then toString(ty.ty); case Type.POLYMORPHIC() - then if Util.stringStartsWith("__", ty.name) then + then if StringUtil.startsWith(ty.name, "__") then substring(ty.name, 3, stringLength(ty.name)) else "<" + ty.name + ">"; case Type.ANY() then "$ANY$"; diff --git a/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo b/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo index 8d79ccf8da6..f23ac67632f 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo @@ -49,6 +49,7 @@ protected import ExpandExp = NFExpandExp; import FlatModelicaUtil = NFFlatModelicaUtil; import IOStream; + import StringUtil; import Util; import Variable = NFVariable; import MetaModelica.Dangerous.listReverseInPlace; @@ -294,7 +295,7 @@ public function isEncrypted input Variable variable; - output Boolean isEncrypted = Util.endsWith(variable.info.fileName, ".moc"); + output Boolean isEncrypted = StringUtil.endsWith(variable.info.fileName, ".moc"); end isEncrypted; function isAccessible diff --git a/OMCompiler/Compiler/NSimCode/NSimCode.mo b/OMCompiler/Compiler/NSimCode/NSimCode.mo index c367ae7f190..2fab83b8309 100644 --- a/OMCompiler/Compiler/NSimCode/NSimCode.mo +++ b/OMCompiler/Compiler/NSimCode/NSimCode.mo @@ -83,6 +83,7 @@ protected // Util imports import Error; + import StringUtil; // Script imports import CevalScriptBackend; diff --git a/OMCompiler/Compiler/NSimCode/NSimStrongComponent.mo b/OMCompiler/Compiler/NSimCode/NSimStrongComponent.mo index c4a1cfc7ade..b1fb975a56c 100644 --- a/OMCompiler/Compiler/NSimCode/NSimStrongComponent.mo +++ b/OMCompiler/Compiler/NSimCode/NSimStrongComponent.mo @@ -80,6 +80,7 @@ protected // Util imports import Error; import Slice = NBSlice; + import StringUtil; public uniontype Block diff --git a/OMCompiler/Compiler/Script/CevalScript.mo b/OMCompiler/Compiler/Script/CevalScript.mo index c0ba1ed7a62..71f31b3959c 100644 --- a/OMCompiler/Compiler/Script/CevalScript.mo +++ b/OMCompiler/Compiler/Script/CevalScript.mo @@ -110,6 +110,7 @@ import Settings; import SimCodeFunction; import StackOverflow; import Static; +import StringUtil; import SymbolTable; import System; import Tpl; @@ -2968,7 +2969,7 @@ algorithm success := false; outFilename := ""; if (System.regularFileExists(filename)) then - if (Util.endsWith(filename, ".mol")) then + if (StringUtil.endsWith(filename, ".mol")) then workdir := if System.directoryExists(inWorkdir) then inWorkdir else System.pwd(); if (skipUnzip or 0 == System.systemCall("unzip -q -o -d \"" + workdir + "\" \"" + filename + "\"")) then s1 := System.basename(filename); diff --git a/OMCompiler/Compiler/Script/CevalScriptBackend.mo b/OMCompiler/Compiler/Script/CevalScriptBackend.mo index 523bfc42308..b29e2553475 100644 --- a/OMCompiler/Compiler/Script/CevalScriptBackend.mo +++ b/OMCompiler/Compiler/Script/CevalScriptBackend.mo @@ -2425,8 +2425,8 @@ algorithm equation pwd = System.pwd(); pd = Autoconf.pathDelimiter; - filename = if System.substring(filename,1,1) == "/" then filename else stringAppendList({pwd,pd,filename}); - filename_1 = if System.substring(filename_1,1,1) == "/" then filename_1 else stringAppendList({pwd,pd,filename_1}); + filename = if StringUtil.startsWith(filename, "/") then filename else stringAppendList({pwd,pd,filename}); + filename_1 = if StringUtil.startsWith(filename_1, "/") then filename_1 else stringAppendList({pwd,pd,filename_1}); strings = TaskGraphResults.checkTaskGraph(filename, filename_1); cvars = List.map(strings,ValuesUtil.makeString); then @@ -2439,8 +2439,8 @@ algorithm equation pwd = System.pwd(); pd = Autoconf.pathDelimiter; - filename = if System.substring(filename,1,1) == "/" then filename else stringAppendList({pwd,pd,filename}); - filename_1 = if System.substring(filename_1,1,1) == "/" then filename_1 else stringAppendList({pwd,pd,filename_1}); + filename = if StringUtil.startsWith(filename, "/") then filename else stringAppendList({pwd,pd,filename}); + filename_1 = if StringUtil.startsWith(filename_1, "/") then filename_1 else stringAppendList({pwd,pd,filename_1}); strings = TaskGraphResults.checkCodeGraph(filename, filename_1); cvars = List.map(strings,ValuesUtil.makeString); then @@ -4175,7 +4175,7 @@ algorithm cdCommand := "cd \"" + dirPath + "\""; mvCommand := "mv \"" + molName +"\" \"" + System.pwd() + "\""; - if (Util.endsWith(fileName, "package.mo")) then + if (StringUtil.endsWith(fileName, "package.mo")) then dirOrFileName := System.basename(dirPath); zipCommand := "zip -r \"" + System.pwd() + pd + molName + "\" \"" + dirOrFileName + "\""; command := stringAppendList({rmCommand, " && ", cdCommand, " && cd .. && ", zipCommand}); diff --git a/OMCompiler/Compiler/Script/Interactive.mo b/OMCompiler/Compiler/Script/Interactive.mo index 4fe1b889684..6a9f7def506 100644 --- a/OMCompiler/Compiler/Script/Interactive.mo +++ b/OMCompiler/Compiler/Script/Interactive.mo @@ -10181,7 +10181,7 @@ algorithm else algorithm - if not Util.stringStartsWith(name, "__") then + if not StringUtil.startsWith(name, "__") then Error.addSourceMessage(Error.CONVERSION_UNKNOWN_ANNOTATION, {name}, info); end if; then @@ -10199,7 +10199,7 @@ algorithm case Absyn.MODIFICATION(path = Absyn.IDENT(name = name), info = info) algorithm - if not Util.stringStartsWith(name, "__") then + if not StringUtil.startsWith(name, "__") then Error.addSourceMessage(Error.CONVERSION_UNKNOWN_ANNOTATION, {name}, info); end if; then @@ -14848,7 +14848,7 @@ protected algorithm try Absyn.CLASS(info=SOURCEINFO(fileName=fileName)) := InteractiveUtil.getPathedClassInProgram(path, p); - encryptedClass := Util.endsWith(fileName, ".moc"); + encryptedClass := StringUtil.endsWith(fileName, ".moc"); if encryptedClass then access := getAccessAnnotation(path, p); if access == "Access.hide" then @@ -14894,7 +14894,7 @@ algorithm end match; for c in classes loop Absyn.CLASS(info=SOURCEINFO(fileName=fileName)) := c; - containsEncryptedClass := containsEncryptedClass or Util.endsWith(fileName, ".moc"); + containsEncryptedClass := containsEncryptedClass or StringUtil.endsWith(fileName, ".moc"); if containsEncryptedClass then break; end if; end for; end astContainsEncryptedClass; diff --git a/OMCompiler/Compiler/Script/Obfuscate.mo b/OMCompiler/Compiler/Script/Obfuscate.mo index 429c21d6df5..6686698e9a4 100644 --- a/OMCompiler/Compiler/Script/Obfuscate.mo +++ b/OMCompiler/Compiler/Script/Obfuscate.mo @@ -36,6 +36,7 @@ encapsulated package Obfuscate import FBuiltin; import SCode; import SCodeUtil; + import StringUtil; import System; import UnorderedMap; import Util; @@ -552,7 +553,7 @@ encapsulated package Obfuscate case "unassignedMessage" then false; case "Protection" then false; case "Authorization" then false; - else not Util.stringStartsWith("__", mod.ident); + else not StringUtil.startsWith(mod.ident, "__"); end match; end isAllowedAnnotation; diff --git a/OMCompiler/Compiler/Script/PackageManagement.mo b/OMCompiler/Compiler/Script/PackageManagement.mo index f37b221c9d8..c804826dfc5 100644 --- a/OMCompiler/Compiler/Script/PackageManagement.mo +++ b/OMCompiler/Compiler/Script/PackageManagement.mo @@ -44,6 +44,7 @@ import Error; import Global; import List; import Settings; +import StringUtil; import System; import Testsuite; import Util; @@ -112,7 +113,7 @@ algorithm end for; for path in listAppend(files, dirs) loop lib := System.basename(path); - if Util.endsWith(lib, ".mo") then + if StringUtil.endsWith(lib, ".mo") then lib := Util.removeLast3Char(lib); end if; first::rest := System.strtok(lib, " "); @@ -488,7 +489,7 @@ algorithm end if; curCachePath := if System.regularFileExists(installCachePath + System.basename(pack.urlToZipFile)) then installCachePath else cachePath; - if Util.endsWith(pack.path, ".mo") then + if StringUtil.endsWith(pack.path, ".mo") then // We are not copying a full directory, so also look for Resources in the zip-file dirOfPath := System.dirname(pack.path); if pack.singleFileStructureCopyAllFiles then @@ -745,12 +746,12 @@ protected String urlWithoutProtocol, newUrl; algorithm urls := {url}; - if not Util.stringStartsWith("https://", url) then + if not StringUtil.startsWith(url, "https://") then return; end if; urlWithoutProtocol := substring(url,9,stringLength(url)); for mirror in mirrors loop - newUrl := if Util.endsWith(mirror, "/") then (mirror + urlWithoutProtocol) else (mirror + "/" + urlWithoutProtocol); + newUrl := if StringUtil.endsWith(mirror, "/") then (mirror + urlWithoutProtocol) else (mirror + "/" + urlWithoutProtocol); urls := newUrl::urls; end for; end getAllUrls; diff --git a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo index 4fc7c5d8207..67cf43622f9 100644 --- a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo +++ b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo @@ -111,6 +111,7 @@ import SimCodeDump; import SimCodeFunctionUtil; import SimCodeFunctionUtil.varName; import Static; +import StringUtil; import SymbolicJacobian; import System; import Util; @@ -15705,9 +15706,9 @@ function getDirectoriesForDLLsFromLinkLibs output list outLibs = {}; algorithm for str in libsAndLinkDirs loop - if Util.stringStartsWith("\"-L", str) then + if StringUtil.startsWith(str, "\"-L") then outLocations := listAppend({System.trim(str, "\"-L")}, outLocations); - elseif Util.stringStartsWith("-l", str) then + elseif StringUtil.startsWith(str, "-l") then outLibs := listAppend({System.trim(str, "-l")}, outLibs); end if; end for; diff --git a/OMCompiler/Compiler/Util/FlagsUtil.mo b/OMCompiler/Compiler/Util/FlagsUtil.mo index 3cffcb49405..6438e030a16 100644 --- a/OMCompiler/Compiler/Util/FlagsUtil.mo +++ b/OMCompiler/Compiler/Util/FlagsUtil.mo @@ -870,8 +870,8 @@ algorithm neg1 := stringEq(stringGetStringChar(inFlag, 1), "-"); neg2 := System.strncmp("no",inFlag,2) == 0; negated := neg1 or neg2; - flag_str := if negated then Util.stringRest(inFlag) else inFlag; - flag_str := if neg2 then Util.stringRest(flag_str) else flag_str; + flag_str := if negated then StringUtil.rest(inFlag) else inFlag; + flag_str := if neg2 then StringUtil.rest(flag_str) else flag_str; setDebugFlag2(flag_str, not negated, inFlags); end setDebugFlag; diff --git a/OMCompiler/Compiler/Util/SemanticVersion.mo b/OMCompiler/Compiler/Util/SemanticVersion.mo index eed60d2b030..bdbc311fc55 100644 --- a/OMCompiler/Compiler/Util/SemanticVersion.mo +++ b/OMCompiler/Compiler/Util/SemanticVersion.mo @@ -33,8 +33,9 @@ encapsulated package SemanticVersion protected -import Util; +import StringUtil; import System; +import Util; public @@ -212,7 +213,7 @@ algorithm end if; if stringGetStringChar(s, 1) == "+" then - metaLst := if stringLength(s) > 1 then Util.stringSplitAtChar(Util.stringRest(s), ".") else {}; + metaLst := if stringLength(s) > 1 then Util.stringSplitAtChar(StringUtil.rest(s), ".") else {}; return; end if; @@ -220,7 +221,7 @@ algorithm prerelease::split := split; meta := if listEmpty(split) then "" else listGet(split, 1); if stringGetStringChar(prerelease, 1) == "-" then - prerelease := Util.stringRest(prerelease); + prerelease := StringUtil.rest(prerelease); end if; prereleaseLst := if stringLength(prerelease) > 0 then Util.stringSplitAtChar(prerelease, ".") else {}; metaLst := if stringLength(meta) > 0 then Util.stringSplitAtChar(meta, ".") else {}; diff --git a/OMCompiler/Compiler/Util/StackOverflow.mo b/OMCompiler/Compiler/Util/StackOverflow.mo index 30223478ce4..214d0a135a7 100644 --- a/OMCompiler/Compiler/Util/StackOverflow.mo +++ b/OMCompiler/Compiler/Util/StackOverflow.mo @@ -33,6 +33,7 @@ encapsulated package StackOverflow protected +import StringUtil; import System; import Testsuite; @@ -41,13 +42,11 @@ function unmangle output String outSymbol; algorithm outSymbol := inSymbol; - if stringLength(inSymbol)>4 then - if substring(inSymbol, 1, 4) == "omc_" then - outSymbol := substring(outSymbol, 5, stringLength(outSymbol)); - outSymbol := System.stringReplace(outSymbol, "__", "#"); - outSymbol := System.stringReplace(outSymbol, "_", "."); - outSymbol := System.stringReplace(outSymbol, "#", "_"); - end if; + if StringUtil.startsWith(inSymbol, "omc_") then + outSymbol := substring(outSymbol, 5, stringLength(outSymbol)); + outSymbol := System.stringReplace(outSymbol, "__", "#"); + outSymbol := System.stringReplace(outSymbol, "_", "."); + outSymbol := System.stringReplace(outSymbol, "#", "_"); end if; end unmangle; diff --git a/OMCompiler/Compiler/Util/StringUtil.mo b/OMCompiler/Compiler/Util/StringUtil.mo index c458e877687..2537cc00813 100644 --- a/OMCompiler/Compiler/Util/StringUtil.mo +++ b/OMCompiler/Compiler/Util/StringUtil.mo @@ -379,33 +379,24 @@ algorithm end for; end stringHashDjb2Work; -function stringAppend9 - input String str1,str2,str3,str4="",str5="",str6="",str7="",str8="",str9=""; - output String str; +function startsWith + input String str; + input String prefix; + output Boolean startsWith = (0 == System.strncmp(str, prefix, stringLength(prefix))); +end startsWith; + +function endsWith + input String str; + input String suffix; + output Boolean endsWith = false; protected - System.StringAllocator sb=System.StringAllocator(stringLength(str1)+stringLength(str2)+stringLength(str3)+stringLength(str4)+stringLength(str5)+stringLength(str6)+stringLength(str7)+stringLength(str8)+stringLength(str9)); - Integer c=0; + Integer str_len = stringLength(str); + Integer suf_len = stringLength(suffix); algorithm - System.stringAllocatorStringCopy(sb, str1, c); - c := c + stringLength(str1); - System.stringAllocatorStringCopy(sb, str2, c); - c := c + stringLength(str2); - System.stringAllocatorStringCopy(sb, str3, c); - c := c + stringLength(str3); - System.stringAllocatorStringCopy(sb, str4, c); - c := c + stringLength(str4); - System.stringAllocatorStringCopy(sb, str5, c); - c := c + stringLength(str5); - System.stringAllocatorStringCopy(sb, str6, c); - c := c + stringLength(str6); - System.stringAllocatorStringCopy(sb, str7, c); - c := c + stringLength(str7); - System.stringAllocatorStringCopy(sb, str8, c); - c := c + stringLength(str8); - System.stringAllocatorStringCopy(sb, str9, c); - c := c + stringLength(str9); - str := System.stringAllocatorResult(sb,str1); -end stringAppend9; + if str_len >= suf_len then + endsWith := 0 == System.strcmp_offset(str, str_len - suf_len + 1, str_len, suffix, 1, suf_len); + end if; +end endsWith; function endsWithNewline input String str; @@ -454,5 +445,11 @@ algorithm end if; end stripFileExtension; +public function rest + "Returns all but the first character of a string." + input String str; + output String rest = substring(str, 2, stringLength(str)); +end rest; + annotation(__OpenModelica_Interface="util"); end StringUtil; diff --git a/OMCompiler/Compiler/Util/Util.mo b/OMCompiler/Compiler/Util/Util.mo index 2fd5d14947b..08d23b0ff10 100644 --- a/OMCompiler/Compiler/Util/Util.mo +++ b/OMCompiler/Compiler/Util/Util.mo @@ -815,14 +815,6 @@ algorithm end try; end writeFileOrErrorMsg; -public function stringStartsWith - input String inString1; - input String inString2; - output Boolean outEqual; -algorithm - outEqual := (0 == System.strncmp(inString1, inString2, stringLength(inString1))); -end stringStartsWith; - public function strncmp "Compare two strings up to the nth character Returns true if they are equal." input String inString1; @@ -1257,17 +1249,6 @@ algorithm end if; end stringPadLeft; -public function stringRest - "Returns all but the first character of a string." - input String inString; - output String outRest; -protected - Integer len; -algorithm - len := stringLength(inString); - outRest := substring(inString, 2, len); -end stringRest; - public function intProduct input list lst; output Integer i = List.fold(lst, intMul, 1); @@ -1447,23 +1428,6 @@ algorithm v := v + 1; end nextPowerOf2; -public function endsWith - input String inString; - input String inSuffix; - output Boolean outEndsWith; -protected - Integer start, stop, str_len, suf_len; -algorithm - if inString == "" then - outEndsWith := false; - else - str_len := stringLength(inString); - suf_len := stringLength(inSuffix); - start := if str_len > suf_len then str_len - suf_len + 1 else 1; - outEndsWith := inSuffix == substring(inString, start, str_len); - end if; -end endsWith; - public function isCIdentifier input String str; output Boolean b; diff --git a/testsuite/simulation/modelica/others/TestSolve18.mos b/testsuite/simulation/modelica/others/TestSolve18.mos index e453cb9cf2c..3058f682acb 100644 --- a/testsuite/simulation/modelica/others/TestSolve18.mos +++ b/testsuite/simulation/modelica/others/TestSolve18.mos @@ -38,7 +38,7 @@ val(z,1.0); // Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->Show additional information from the initialization process, in OMNotebook call setCommandLineOptions(\"-d=initialization\"). // [BackEnd/ExpressionSolve.mo:0:0-0:0:writable] Error: Internal error Failed to solve \"time = -1.0 + y * exp(if y > 0.0 then time else 2.0 * time)\" w.r.t. \"y\" // [BackEnd/ExpressionSolve.mo:0:0-0:0:writable] Error: Internal error Failed to solve \"time = 5.0 * (-1.0 + exp(/*Real*/(sign(1.0 + 2.0 * x))))\" w.r.t. \"x\" -// [BackEnd/Differentiate.mo:202:7-202:147:writable] Error: Derivative of expression \"der(z) - (x - y)\" w.r.t. \"z\" is non-existent. +// [BackEnd/Differentiate.mo:203:7-203:147:writable] Error: Derivative of expression \"der(z) - (x - y)\" w.r.t. \"z\" is non-existent. // [BackEnd/ExpressionSolve.mo:0:0-0:0:writable] Error: Internal error Failed to solve \"der(z) = x - y\" w.r.t. \"z\" // " // -1.5