Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve fault-tolerance of Modelica.Utilities.Strings.substring w.r.t. index arguments and remove undocumented case with endIndex=-999 #3503

Merged
merged 4 commits into from
Jul 9, 2020

Conversation

beutlich
Copy link
Member

I missed the feature of Modelica.Utilities.Strings.substring to return an empty string. This is why I started this PR.

  • Do not assert on incorrect arguments of substring, but try to correct them and raise a warning instead.
  • substring was also improved to return an empty string, in case endIndex is less than startIndex.

@beutlich beutlich added enhancement New feature or enhancement L: Utilities Issue addresses Modelica.Utilities labels Mar 15, 2020
@beutlich beutlich added this to the MSL4.0.1 milestone Mar 15, 2020
@beutlich beutlich self-assigned this Mar 15, 2020
@beutlich beutlich changed the title Improve fault-tolerance of Modelica.Utilities.Strings.substring w.r.t.index arguments Improve fault-tolerance of Modelica.Utilities.Strings.substring w.r.t. index arguments Mar 15, 2020
Copy link
Contributor

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea overall.
However,

  1. startIndex=0 is illegal, but not "negative" I would use the phrase "non-positive"
  2. I'm unsure if we totally should ignore messages for endIndex>length. Using startIndex=2 endIndex=9999999 (or a symbol for the latter) seems like a simple way to skip the first character.

@beutlich beutlich changed the title Improve fault-tolerance of Modelica.Utilities.Strings.substring w.r.t. index arguments Improve fault-tolerance of Modelica.Utilities.Strings.substring w.r.t. index arguments and remove undocumented case with endIndex=-999 Mar 15, 2020
Copy link
Contributor

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Although I see some unrelated changes (I assume due to merging).

@beutlich beutlich requested a review from sjoelund May 4, 2020 07:27
@beutlich beutlich modified the milestones: MSL4.0.1, MSL4.1.0 May 26, 2020
@beutlich beutlich requested review from sjoelund and DagBruck and removed request for sjoelund and DagBruck May 26, 2020 17:55
@beutlich
Copy link
Member Author

@sjoelund @DagBruck Can you please do the review. Thanks.

Copy link
Contributor

@casella casella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the idea of making this function more tolerant.

I agree with @HansOlsson that you should replace "negative" with "non-positive" or "less than one" in the warning when startIndex < 1

@casella
Copy link
Contributor

casella commented Jul 8, 2020

@sjoelund is on holiday

* Do not assert on incorrect arguments of substring, but try to correct them and raise a warning instead.
* substring was also improved to return an empty string, in case endIndex is less than startIndex.
@beutlich
Copy link
Member Author

beutlich commented Jul 9, 2020

I agree with @HansOlsson that you should replace "negative" with "non-positive" or "less than one" in the warning when startIndex < 1

That should be the case already.

@beutlich beutlich merged commit 4929e97 into modelica:master Jul 9, 2020
@beutlich beutlich deleted the update-substring branch July 9, 2020 14:49
beutlich added a commit to beutlich/ModelicaStandardLibrary that referenced this pull request Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement L: Utilities Issue addresses Modelica.Utilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants