-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Strings - added method cut() #20
Conversation
👎 Toooooo magic. |
What? |
@@ -130,6 +130,43 @@ public static function substring($s, $start, $length = NULL) | |||
|
|||
|
|||
/** | |||
* Returns cutted string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @Majkl578. The name is not much descriptive and the functionality is too complicated.
|
What I like about Nette is that almost every feature is powerful yet very simple to grasp. I am afraid 99% of users will never learn (I mean remember how to use it) such method. 👎 |
@icaine One number and two booleans are really much. E.g. $sub = Some::cut($path, '/') . '/'; and it is obvious. TRUE or FALSE as 5th parameter is just magic. If I understand well, you need it to work with filesystem path mostly. Would not be If so, do you really need more than |
The name may not be the best and if you give me any better i dont see a problem. The reason why i made this method is that i always was confused with |
I understand u. What with the Tooooo many arguments problem? |
What with it? Lesser arguments means lesser functionality. If all were mandatory i would understand your cooooomplains, but they are not.. Anyway, the community refused it.. closed.. |
@icaine you give up too easily :) |
Such PRs are about discussion, not about getting anger after first wave of disagreement. ;) |
@icaine Problem with too many arguments is that they are not understandable. For example, what do you think this is doing? |
What about split it to multiple methods with better names. Something like:
Internaly it still can call same function with many parameters parameters but it will be private. Example: echo Strings::before("some long string", "long"); // -> "some"
echo Strings::until("some long string", "long"); // -> "some long"
echo Strings::past("some long string", "long"); // -> "long string"
echo Strings::after("some long string", "long"); // -> "string" |
👍 Good idea... Maybe the before and after methods could take second argument |
I personally don't like boolean parameters. From my POV more methods with clear names are better. |
@MartinMystikJonas i like it... So before ($haystack, $needle, $nth = 1)
after ($haystack, $needle, $nth = 1)
// and maybe these
until ($haystack, $needle, $nth = 1)
past ($haystack, $needle, $nth = 1)
// OR
before ($haystack, $needle, $nth = 1, $includeNeedle = false)
after ($haystack, $needle, $nth = 1, $includeNeedle = false) |
Is there any use-case, where $nth is greater than 1? |
Well I can imagine something like: after("/some/long/absolute/path/to/file", "/", 3); // -> "path/to/file" |
@MartinMystikJonas And how would you know that you should always skip 3 directories? |
On this was not best example. Let my try again :-) Lets say we have some data storage where each user has his own folder for personal data and you want to show him only part of path he is interested to.
Or you can compute $nth parameter somehow. |
@JanTvrdik it's similar to using |
And in the case that there are only two slashes, I think that more expectable is to return FALSE. You can always use |
It returns false. |
I'd like this: after('some.long.file.name.jpg', '.', -1); // jpg |
5617d88
to
209844d
Compare
Remove en/book
Purpose of this method is to simplify usage when functions like
strstr()
andstrrchr()
are need.