lib/marc_cleanup/bib_rubymarc_fixes.rb
### Normalize to the NFC (combined) form of diacritics for characters with
#     Arabic diacritics; normalize to NFD for characters below U+622 and
#     between U+1E00 and U+2A28
Normalize to the NFC (combined) form of diacritics for characters with
Arabic diacritics; normalize to NFD for characters below U+622 and
between U+1E00 and U+2A28
Normalize to the NFC ( combined ) form of diacritics for characters with Arabic diacritics ; normalize to NFD for characters below U + 622 and between U + 1E00 and U + 2A28
def composed_chars_normalize(record)
    record.fields.each do |field|
      next unless field.class == MARC::DataField
      field_index = record.fields.index(field)
      curr_subfield = 0
      field.subfields.each do |subfield|
        fixed_subfield = ''
        prevalue = subfield.value
        if prevalue =~ /^.*[\u0653\u0654\u0655].*$/
          prevalue = prevalue.unicode_normalize(:nfc)
        end
        prevalue.each_codepoint do |c|
          char = c.chr(Encoding::UTF_8)
          char.unicode_normalize!(:nfd) if c < 1570 || (7_680..10_792).cover?(c)
          fixed_subfield << char
        end
        record.fields[field_index].subfields[curr_subfield].value = fixed_subfield
        curr_subfield += 1
      end
    end
    record
  end
def composed_chars_normalize ( record ) record . fields . each do | field | next unless field . class == MARC :: DataField field_index = record . fields . index ( field ) curr_subfield = 0 field . subfields . each do | subfield | fixed_subfield = '' prevalue = subfield . value if prevalue =~ / ^.*[ \u0653 \u0654 \u0655 ].*$ / prevalue = prevalue . unicode_normalize ( :nfc ) end prevalue . each_codepoint do | c | char = c . chr ( Encoding :: UTF_8 ) char . unicode_normalize! ( :nfd ) if c < 1570 || ( 7_680 .. 10_792 ) . cover? ( c ) fixed_subfield << char end record . fields [ field_index ] . subfields [ curr_subfield ] . value = fixed_subfield curr_subfield += 1 end end record end
Normalize to the NFC (combined) form of diacritics for characters with
Arabic diacritics; normalize to NFD for characters below U+622 and
between U+1E00 and U+2A28
Normalize to the NFC ( combined ) form of diacritics for characters with Arabic diacritics ; normalize to NFD for characters below U + 622 and between U + 1E00 and U + 2A28
record