ncr
Version:
A parser and converter for Unicode Characters, including (standard and extended) Numerical Character References
82 lines (65 loc) • 3.88 kB
text/coffeescript
############################################################################################################
CND = require 'cnd'
rpr = CND.rpr.bind CND
badge = 'CHR/XNCR'
log = CND.get_logger 'plain', badge
info = CND.get_logger 'info', badge
alert = CND.get_logger 'alert', badge
debug = CND.get_logger 'debug', badge
warn = CND.get_logger 'warn', badge
whisper = CND.get_logger 'whisper', badge
help = CND.get_logger 'help', badge
echo = CND.echo.bind CND
#...........................................................................................................
CHR = require './main'
### TAINT there should be a unified way to obtain copies of libraries with certain settings that
differ from that library's default options. Interface could maybe sth like this:
```
settings = _.deep_copy CHR.options
settings[ 'input' ] = 'xncr'
XNCR_CHR = OPTIONS.new_library CHR, settings
```
###
### TAINT additional settings silently ignored ###
#-----------------------------------------------------------------------------------------------------------
settings = { input: 'xncr' }
#...........................................................................................................
= ( glyph ) -> CHR.analyze glyph, settings
= ( glyph ) -> CHR.as_csg glyph, settings
= ( glyph ) -> CHR.as_chr glyph, settings
= ( glyph ) -> CHR.as_uchr glyph, settings
= ( glyph ) -> CHR.as_cid glyph, settings
= ( glyph ) -> CHR.as_rsg glyph, settings
= ( glyph ) -> CHR.as_sfncr glyph, settings
= ( glyph ) -> CHR.as_fncr glyph, settings
# = ( csg, cid ) -> CHR._as_xncr csg, cid
= ( text ) -> CHR.chrs_from_text text, settings
= ( glyph ) -> ( glyph ) in [ 'u', 'jzr', ]
= ( cid, csg ) -> CHR.as_chr cid, { csg: csg }
= ( rsg ) -> CHR.cid_range_from_rsg rsg
= ( glyph ) -> CHR.html_from_text glyph, settings
#-----------------------------------------------------------------------------------------------------------
= ( glyph ) ->
return glyph if ( glyph ) is 'jzr'
return glyph
#-----------------------------------------------------------------------------------------------------------
= ( text ) -> ( g for g in text ).join ''
#-----------------------------------------------------------------------------------------------------------
= ( glyph ) ->
# alert "XNCR.normalize is deprecated"
rsg = glyph
cid = glyph
csg = glyph
return cid, 'u' if ( rsg is 'u-pua' ) or ( csg in [ 'u', 'jzr', ] )
return glyph
#-----------------------------------------------------------------------------------------------------------
= ( glyph ) ->
cid = glyph
csg = if ( glyph ) is 'u-pua' then 'jzr' else glyph
return cid, csg
#-----------------------------------------------------------------------------------------------------------
= ( glyph ) ->
cid = glyph
csg = glyph
csg = 'u' if csg is 'jzr'
return cid, csg