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

beginswith, endswith accept Chars #6779

Merged
merged 1 commit into from
May 13, 2014

Conversation

WestleyArgentum
Copy link
Member

I noticed that rstrip and others accept Chars, it only seems fair if endswith, beginswith do the same.

Consider trying to strip punctuation from the end of a sentence:

if endswith(sentence, ['.','?','!'])
    sentence = chop(sentence)
end

beginswith(a::String, c::Char) = !isempty(a) && a[start(a)] == c

function beginswith(str::String, chars::Chars)
if !isempty(str)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

How about !isempty(str) && str[start(str)] in chars && return true?

Copy link
Member Author

Choose a reason for hiding this comment

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

very nice, I'll update

@WestleyArgentum
Copy link
Member Author

Done - I think that's good now

@JeffBezanson
Copy link
Sponsor Member

Needs a doc update. Actually the docs for rstrip, lstrip, and strip need a similar update while you're at it.

JeffBezanson added a commit that referenced this pull request May 13, 2014
beginswith, endswith accept Chars
@JeffBezanson JeffBezanson merged commit a52d51a into JuliaLang:master May 13, 2014
@ivarne
Copy link
Sponsor Member

ivarne commented May 13, 2014

Where did the documentation update go?

@JeffBezanson
Copy link
Sponsor Member

I did it.

@ivarne
Copy link
Sponsor Member

ivarne commented May 13, 2014

Sorry, I found 57a0aa7 now :-)

vtjnash pushed a commit that referenced this pull request Feb 10, 2024
Since Julia 0.3 (#6779), the `startswith` and `endswith` functions have
accepted not only a string as the prefix/suffix, but also a character or
a tuple/vector/set of characters. However, this wasn't fully documented.

(The docstring actually mentioned vectors and sets of characters, but
this was inconsistent with the given signature.)

Also updates `Base.Chars` to allow `AbstractSet` types, not just `Set`,
which seems to have been an oversight.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants