Skip to content

Commit

Permalink
flush encoder less often (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored May 11, 2023
1 parent 42f85e2 commit a799333
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/StripRTF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function _striprtf(out::IO, text::String)
encoder = out
for match in eachmatch(PATTERN, text)
word, arg, hex, char, brace, tchar = match.captures
hex === nothing && encoder !== out && flush(encoder) # convert codepage bytes to UTF-8
if brace !== nothing
curskip = 0
if brace == "{"
Expand All @@ -125,9 +126,9 @@ function _striprtf(out::IO, text::String)
curskip = 0
ch = only(char)
if ch == '~'
!ignorable && (flush(encoder); print(out, '\ua0'))
!ignorable && print(out, '\ua0')
elseif ch in "{}\\\n\r"
!ignorable && (flush(encoder); print(out, char))
!ignorable && print(out, char)
elseif ch == '*'
ignorable = true
end
Expand All @@ -143,15 +144,15 @@ function _striprtf(out::IO, text::String)
elseif ignorable
nothing
elseif word in keys(specialchars)
flush(encoder); print(out, specialchars[word])
print(out, specialchars[word])
elseif word == "uc"
ucskip = parse(Int, arg)
elseif word == "u"
# because of https://github.com/joshy/striprtf/issues/6
if arg !== nothing
c = parse(Int, arg)
c < 0 && (c += 0x10000)
flush(encoder); print(out, Char(c))
print(out, Char(c))
end
curskip = ucskip
end
Expand All @@ -166,7 +167,7 @@ function _striprtf(out::IO, text::String)
if curskip > 0
curskip -= 1
elseif !ignorable
flush(encoder); print(out, tchar)
print(out, tchar)
end
end
end
Expand Down

2 comments on commit a799333

@stevengj
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request updated: JuliaRegistries/General/83294

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" a7993333aaa7083d12471084f740b1e1fe15155d
git push origin v1.0.0

Please sign in to comment.