If file is empty then result <tag></tag> although expected empty string.
brianSat 8 Jan 2011
Some nice ideas. Here are my thoughts:
Uri has plusName, plusName, plusQuery, plusSlash except plusExt.
The reason is that you typically need to do some string manipulation. Very rarely would you stick an extension on a URI without stripping the existing ext right?
uri := `foo/file.txt`
uri.parent + `${uri.basename}.newext`
Maybe a replaceExt might make more sense, although even that seems pretty rare.
@Operator div for Uri.
That is interesting idea. Seems a bit like operator abuse, but I'd be interested to hear what others think?
There is File.readAllStr but there is no File.writeAllStr.
I thought about adding something like that to OutStream and File, but decided against it because it such an easy one liner:
file.print(str).close
I guess technically you could make the case that isn't guaranteed to close the stream, but exceptions on output streaming are sort of an odd case. Other thoughts?
Better if "".splitLines returns empty list instead of list with one empty string. Current behavior confused me.
The problem is that "" is a string with one line. Consider these cases:
The problem is that there is a difference b/w "line1" and "line1\n", the second actually does have a second line even though it is empty.
andySat 8 Jan 2011
The "".splitLines case bites me quite a bit - so I would welcome a change here - even if its just an additional parameter (or method) - the workaround today is sorta a pain.
brianSat 8 Jan 2011
The "".splitLines case bites me quite a bit - so I would welcome a change here - even if its just an additional parameter (or method) - the workaround today is sorta a pain.
I guess we could implicitly remove the last line if it was empty or add another flag for it. Anybody have an issue with that breaking change?
cheeserSun 9 Jan 2011
That would break things like a line count just off the top of my head. "line\n" is 2 lines not 1. Removing that implicitly would introduce some subtle bugs, imo. If you added a flag, would it apply only to trailing empty elements? What about empty elements in the middle?
For reference:
cat Split.java && java Split
public class Split {
public static void main(String[] args) {
System.out.println("".split("\n").length);
}
}
1
About -2- Personally I think Fantom could endure more operator abuse (like concat for List that would shortcut to a plus). So +1 to -2-.
As for the -4- maybe another method is in order(splitNonEmpty)?
andySun 9 Jan 2011
I think you simply make a special case for "" - otherwise works as it does today.
heliumSun 9 Jan 2011
-1 to making a special case for "".
MoOmSun 9 Jan 2011
-1 for operator abuse.
ivanMon 10 Jan 2011
-1 for div. `$root/$category/$item` does the trick.
andyMon 10 Jan 2011
-1 for div - as ivan said, interpolation works just fine here.
After some thought, I think a skipEmpty param for splitLines would work just fine. In general, if "" was not valid, other empty lines probably aren't either. So keeps the (assuming) common case simple.
Akcelisto Sat 8 Jan 2011
-1-
Uri
hasplusName
,plusName
,plusQuery
,plusSlash
exceptplusExt
.Suggestion:
Uri.plusExt(Str ext)
-2-
@Operator div
forUri
. Using:-3-
There is
File.readAllStr
but there is noFile.writeAllStr
.Suggestion:
File.writeAllStr(Str str)
writes str in file and closes fileInStream
.-4-
Better if
"".splitLines
returns empty list instead of list with one empty string. Current behavior confused me.Lets need to count amount of lines in file:
If file is empty then result
1
although expected0
.Lets need to wrap up lines in file by tag:
If file is empty then result
<tag></tag>
although expected empty string.brian Sat 8 Jan 2011
Some nice ideas. Here are my thoughts:
The reason is that you typically need to do some string manipulation. Very rarely would you stick an extension on a URI without stripping the existing ext right?
Maybe a replaceExt might make more sense, although even that seems pretty rare.
That is interesting idea. Seems a bit like operator abuse, but I'd be interested to hear what others think?
I thought about adding something like that to OutStream and File, but decided against it because it such an easy one liner:
I guess technically you could make the case that isn't guaranteed to close the stream, but exceptions on output streaming are sort of an odd case. Other thoughts?
The problem is that "" is a string with one line. Consider these cases:
The problem is that there is a difference b/w "line1" and "line1\n", the second actually does have a second line even though it is empty.
andy Sat 8 Jan 2011
The
"".splitLines
case bites me quite a bit - so I would welcome a change here - even if its just an additional parameter (or method) - the workaround today is sorta a pain.brian Sat 8 Jan 2011
I guess we could implicitly remove the last line if it was empty or add another flag for it. Anybody have an issue with that breaking change?
cheeser Sun 9 Jan 2011
That would break things like a line count just off the top of my head. "line\n" is 2 lines not 1. Removing that implicitly would introduce some subtle bugs, imo. If you added a flag, would it apply only to trailing empty elements? What about empty elements in the middle?
For reference:
Akcelisto Sun 9 Jan 2011
I think:
DanielFath Sun 9 Jan 2011
About -2- Personally I think Fantom could endure more operator abuse (like concat for List that would shortcut to a plus). So +1 to -2-.
As for the -4- maybe another method is in order(
splitNonEmpty
)?andy Sun 9 Jan 2011
I think you simply make a special case for
""
- otherwise works as it does today.helium Sun 9 Jan 2011
-1 to making a special case for "".
MoOm Sun 9 Jan 2011
-1 for operator abuse.
ivan Mon 10 Jan 2011
-1 for div.
`$root/$category/$item`
does the trick.andy Mon 10 Jan 2011
-1 for
div
- as ivan said, interpolation works just fine here.After some thought, I think a
skipEmpty
param forsplitLines
would work just fine. In general, if""
was not valid, other empty lines probably aren't either. So keeps the (assuming) common case simple.brian Mon 10 Jan 2011
original retracted
I just should note that splitLines actually works consistently with split, and I don't think we want to break consistency b/w those: