Skip to content

Replace recursion with iteration in UnicodeNormalize.nfc_one #13957

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Replace recursion with iteration in UnicodeNormalize.nfc_one
  • Loading branch information
sferik committed Jul 22, 2025
commit 717f5c91b3c9718736023fd30aa7de62ec9dc5da
22 changes: 20 additions & 2 deletions lib/unicode_normalize/normalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,26 @@ def self.nfc_one(string)
last_class = accent_class
end
end
accents = nfc_one(accents) if accents.length>1 # TODO: change from recursion to loop
hangul_comp_one(start+accents)

result = start
until accents.empty?
start = accents[0]
last_class = CLASS_TABLE[start]-1
rest = ''
accents[1..-1].each_char do |accent|
accent_class = CLASS_TABLE[accent]
if last_class < accent_class && (composite = COMPOSITION_TABLE[start + accent])
start = composite
else
rest << accent
last_class = accent_class
end
end
result << start
accents = rest
end

hangul_comp_one(result)
end

def self.normalize(string, form = :nfc)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy