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

Add Str::start() and str_start helper function #20569

Merged
merged 1 commit into from Aug 15, 2017

Conversation

Projects
None yet
6 participants
@calebporzio
Contributor

calebporzio commented Aug 15, 2017

What's life if you can't PR string helper functions - amiright?

With some naming help from twitter and @adamwathan, I planned on PRing str_prefix and str_suffix (Those were the helper functions @DanielCoulbourne and I talked about on the podcast) as a cure for the common and gnarly looking ltrim($path, '/').'/' and rtrim($path, '/').'/', but upon writing up tests discovered str_finish face palm

I often need this sort of thing when dealing with urls and paths. Hopefully the need is felt.

Long live the string helper!

@taylorotwell taylorotwell merged commit a9ed75c into laravel:5.4 Aug 15, 2017

2 checks passed

continuous-integration/styleci/pr The StyleCI analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell Aug 15, 2017

Member

I accept your string helper offering.

Member

taylorotwell commented Aug 15, 2017

I accept your string helper offering.

@DanielCoulbourne

This comment has been minimized.

Show comment
Hide comment
@DanielCoulbourne

DanielCoulbourne Aug 15, 2017

Contributor

Proud of you bud.

Contributor

DanielCoulbourne commented Aug 15, 2017

Proud of you bud.

@adamwathan

This comment has been minimized.

Show comment
Hide comment
@adamwathan

adamwathan Aug 15, 2017

Member

Should benchmark the regex implementation in this and finish; makes sense to replicate the finish implementation but I can't help but think it's total overkill in both situations vs. ltrim and rtrim.

If the code was significantly simpler with the regex I wouldn't even say anything, but actually feels more complicated than this:

return $prefix.ltrim($value, $prefix);

Maybe there's some other reason it needs to be fancy though? Entirely possible!

(FWIW I would have PR'd it the exact same way you did, to be clear 😄)

Member

adamwathan commented Aug 15, 2017

Should benchmark the regex implementation in this and finish; makes sense to replicate the finish implementation but I can't help but think it's total overkill in both situations vs. ltrim and rtrim.

If the code was significantly simpler with the regex I wouldn't even say anything, but actually feels more complicated than this:

return $prefix.ltrim($value, $prefix);

Maybe there's some other reason it needs to be fancy though? Entirely possible!

(FWIW I would have PR'd it the exact same way you did, to be clear 😄)

@wilburpowery

This comment has been minimized.

Show comment
Hide comment
@wilburpowery

wilburpowery Aug 16, 2017

The helper man. Congrats @calebporzio 👌🏻

wilburpowery commented Aug 16, 2017

The helper man. Congrats @calebporzio 👌🏻

@vlakoff

This comment has been minimized.

Show comment
Hide comment
@vlakoff

vlakoff Aug 16, 2017

Contributor

@adamwathan The trim methods work on single chars (the string is a "mask").

e.g. trim('foobar', 'afr') returns oob

Contributor

vlakoff commented Aug 16, 2017

@adamwathan The trim methods work on single chars (the string is a "mask").

e.g. trim('foobar', 'afr') returns oob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment