module NRSER::Char
Declarations
¶ ↑
A place to put things that work with characters.
**_This is ALL based around UTF-8 by default_**
Constants
- ALL_CONTROL_RE
{Regexp} that matches when all characters are control characters.
NOTE This will match the empty string.
@return [Regexp]
- CONTROL_RE
{Regexp} that matches a control character.
@return [Regexp]
- HEX_RE
- NULL
Special
character info for theNULL
character (zero byte in string).@return [NRSER::Char::Special]
Public Class Methods
Test if string is a control character (returns `false` if length > 1).
@param [String] char
String to test.
@return [Boolean]
`true` if `char` is a control character.
# File lib/nrser/char.rb, line 77 def self.control? char char.length == 1 && CONTROL_RE.match( char ) end
Convert hex string to UTF-8 character (length 1 string).
@param [String | Integer] source
Hexadecimal (base-16) number represented as a string or a non-negative integer.
@return [String]
UTF-8 character.
@raise (see .from_hex)
# File lib/nrser/char.rb, line 131 def self.from source case source when HEX_RE from_hex source when Integer from_i source else raise ArgumentError.new binding.erb <<-END Expected hex String like '12AB' or Integer, got <%= source.class %>: <%= source.pretty_inspect %> END end end
Convert hex string to UTF-8 character (length 1 string).
@param [String] hex
Hexadecimal (base-16) number represented as a string.
@return [String]
UTF-8 character.
@raise
When conversion can't be performed.
# File lib/nrser/char.rb, line 115 def self.from_hex hex from_i hex.to_i( 16 ) end
Convert integer to UTF-8 character (length 1 string).
@param [Integer] int
Integer (decimal/base-10) representation of the character.
@return [String]
UTF-8 character.
@raise
When conversion can't be performed.
# File lib/nrser/char.rb, line 96 def self.from_i int int.chr Encoding::UTF_8 end