-
Notifications
You must be signed in to change notification settings - Fork 94
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
Added Extend
and various FromIterator
implementations to CslStringList
.
#457
Conversation
@lnicola @jdroenner r+? |
Sorry, I was away for the past couple of days. I'll take a look tomorrow. |
@@ -1,3 +1,12 @@ | |||
<PAMDataset> | |||
<SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS> | |||
<PAMRasterBand band="1"> |
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 don't remember if we want this or not, but perhaps it's harmless.
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.
it doesn't affect the tests. I got tired of reseting the file every time I ran tests.
} | ||
} | ||
|
||
impl Extend<CslStringListEntry> for CslStringList { |
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.
Too bad we can't use CSLMerge
here.
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 actually started to implement it (and still can) but the C++ implementation scared me as I saw no evidence that it would extend the length of the original array. That said, my C++ is 20 years rusty.
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.
That function just appends one element at a time.
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.
Couldn't find a {re|m}alloc
in there or in CSLSetNameValue
either.
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.
impl Extend<CslStringListEntry> for CslStringList { | ||
fn extend<T: IntoIterator<Item = CslStringListEntry>>(&mut self, iter: T) { | ||
for e in iter { | ||
self.add_entry(&e).unwrap_or_default(); |
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.
Oof 😔.
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.
@lnicola Here's my rational as to why this might be OK.
Most of the time you're going to be extending one CslStringList
with another. The only way that call can fail is if your insertion String
has \r
, \n
, or most importantly \0
. If iter
comes from a CslStringList
then that validation has already happened.
However, if iter
comes from [CslStringListEntry]
, then you could presumably circumvent that check. I added this comment for that reason.
The obvious alternative means no Extend
, and TryFrom
s to cover what is probably a rare edge case. On balance, I'd rather have Extend
.
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.
Exactly. OOM might be another case where it fails, but it's pretty unlikely.
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.
FWIW, Added additional documentation to CslStringListEntry::new_{pair|flag}
.
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.
The error handling makes this a bit icky, but I don't have any good suggestions.
I think it's workable, if not ideal, let's see how jdroenner, feels about it.
@jdroenner r+? |
/// | ||
/// An Entry is ether a single token (`Flag`), or a `name=value` assignment (`Pair`). | ||
/// | ||
/// Note: When constructed directly, assumes string values do not contain newline characters nor |
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.
We should probably spell out more clearly that those values will be ignored. And not just here, but also on CslStringList
.
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.
CslStringList
actually propagates the error.
Lines 116 to 117 in 16f2aef
Self::check_valid_name(name)?; | |
Self::check_valid_value(value)?; |
to `CslStringList`.
caa66a6
to
ff6a0e3
Compare
bors r=lnicola |
bors try |
CHANGES.md
if knowledge of this change could be valuable to users.Addresses some leftover feedback from here.
The docs summarize what this PR enables: