Skip to content
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

Feature/Unicode escape support #166

Merged
merged 26 commits into from
May 27, 2021

Conversation

karljj1
Copy link
Collaborator

@karljj1 karljj1 commented May 21, 2021

We often want to write Unicode escape characters in our text e.g \u2022 will become •.
This adds support to the Parser and LiteralText to handle Unicode in the form \uXXXX
I also fixed some typos in the surrounding code.


// Is this a unicode escape sequence?
if (i + 1 < format.Length && format[i + 1] == 'u')
lastI = i + 6; // \u0000 format
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be safe to do
i += 6 and break here to save having to iterate over the numbers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safe enough. It's the same as with other escaped characters. Illegal escape sequences throw when trying to unescape the literal by the formatter. I don't see an advantage already throwing in the parser.

@codecov
Copy link

codecov bot commented May 21, 2021

Codecov Report

Merging #166 (06c47eb) into version/v3.0 (0939db0) will increase coverage by 0%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           version/v3.0   #166   +/-   ##
===========================================
  Coverage            94%    95%           
===========================================
  Files                42     42           
  Lines              1826   1839   +13     
===========================================
+ Hits               1725   1738   +13     
  Misses              101    101           
Impacted Files Coverage Δ
src/SmartFormat/Core/Parsing/EscapedLiteral.cs 100% <100%> (ø)
src/SmartFormat/Core/Parsing/Parser.cs 96% <100%> (+<1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0939db0...06c47eb. Read the comment docs.

@axunonb
Copy link
Member

axunonb commented May 24, 2021

Very nice, thanks! Should definitely become part of SF.
While working on the v3 branch I wouldn't like to implement new features into v2.
Currently, the PR doesn't combine with the modified parser of v3.

@axunonb axunonb added this to the version/v3 milestone May 24, 2021
@axunonb axunonb changed the base branch from main to unicode-escape-support-v3 May 25, 2021 16:12
@axunonb axunonb marked this pull request as draft May 25, 2021 16:17
@axunonb axunonb changed the base branch from unicode-escape-support-v3 to version/v3.0 May 27, 2021 12:51
@axunonb axunonb marked this pull request as ready for review May 27, 2021 14:13
@axunonb axunonb merged commit 800d52d into axuno:version/v3.0 May 27, 2021
axunonb pushed a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
* Added support for Unicode Escape sequences
* Updated test with unicode escape sequence support and fixed some typos
* Fixed typo
* Some additional tests to keep code coverage happy
* Rebased to version/v3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants