Auto merge of #13914 - TooManyBees:13894-use-graphemes, r=emilio

13894 Use graphenes in text-emphasis-style

<!-- Please describe your changes on the following line: -->
Use `unicode_segmentation` crate to truncate strings on grapheme boundaries.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13894 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13914)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-27 15:58:17 -05:00 committed by GitHub
commit b4a882f81a
7 changed files with 32 additions and 1 deletions

View file

@ -741,6 +741,7 @@ ${helpers.single_keyword("text-align-last",
use computed_values::writing_mode::T as writing_mode;
use cssparser::ToCss;
use std::fmt;
use unicode_segmentation::UnicodeSegmentation;
use values::LocalToCss;
use values::NoViewportPercentage;
@ -889,7 +890,9 @@ ${helpers.single_keyword("text-align-last",
},
SpecifiedValue::None => computed_value::T::None,
SpecifiedValue::String(ref s) => {
let string = s.chars().next().as_ref().map(ToString::to_string).unwrap_or_default();
// Passing `true` to iterate over extended grapheme clusters, following
// recommendation at http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries
let string = s.graphemes(true).next().unwrap_or("").to_string();
computed_value::T::String(string)
}
}