\Malenki\BahC

Define a single character.

Unlike other classes of Bah library, this class is not equivalent of a PHP primitive type, but it can be very useful to deal with characters and their UTF-8 properties.

So, you can tests some characters properties, such as "is ti punctuation?"; "is it lowercase?"; "is it right to left character?" and many others…

You can get all characters from family of given one (from same unicode block), you can get unicode code point and block name for each character.

Summary

Methods
Properties
Constants
__get()
__toString()
__construct()
encodings()
$bytes
$to_s
$to_n
$string
$str
$integer
$int
$upper
$lower
$unicode
$rtl
$is_rtl
$right_to_left
$is_right_to_left
$ltr
$is_ltr
$left_to_right
$is_left_to_right
$
ENCODING
mustBeStringOrScalar()
mustBeString()
mustBeInteger()
mustBeFloat()
mustBeDouble()
mustBeNumeric()
mustBeArray()
mustBeHash()
mustBeArrayOrHash()
mustBeCallable()
_string()
_str()
_integer()
_int()
_trans()
_upper()
_lower()
_isLetter()
_isDigit()
_isControl()
_isFormat()
_isUnassigned()
_isPrivateUse()
_isSurrogate()
_isMark()
_isSeparator()
_isPunctuation()
_isSymbol()
_isLowerCase()
_isLower()
_isUpperCase()
_isUpper()
_isAscii()
_hasCase()
_block()
_family()
_unicode()
_rtl()
_ltr()
$value
$arr_blocks
$col_bytes
$bool_is_surrogate
N/A
No private methods found
No private properties found
N/A

Constants

ENCODING

ENCODING

Properties

$bytes

$bytes : \Malenki\Bah\Malenki\Bah\A

A collection of Malenki\Bah\N objects

Type

\Malenki\Bah\Malenki\Bah\A

$to_s

$to_s : \Malenki\Bah\Malenki\Bah\S

Converted version of character as Malenki\Bah\S object.

Type

\Malenki\Bah\Malenki\Bah\S

$to_n

$to_n : \Malenki\Bah\Malenki\Bah\N

Converted version of character as Malenki\Bah\N object. Be careful: if it is not a digit, then this raises an exception.

Type

\Malenki\Bah\Malenki\Bah\N

$string

$string : string

Cast to primitive string

Type

string

$str

$str : string

Cast to primitive string

Type

string

$integer

$integer : integer

Cast to primitive integer, if possible

Type

integer

$int

$int : integer

Cast to primitive integer, if possible

Type

integer

$upper

$upper : \Malenki\Bah\C

Convert current character to uppercase

Type

\Malenki\Bah\C

$lower

$lower : \Malenki\Bah\C

Convert current character to lowercase

Type

\Malenki\Bah\C

$unicode

$unicode : \Malenki\Bah\N

Gets unicode code point

Type

\Malenki\Bah\N

$rtl

$rtl : boolean

True if it is a right to left character

Type

boolean

$is_rtl

$is_rtl : boolean

True if it is a right to left character

Type

boolean

$right_to_left

$right_to_left : boolean

True if it is a right to left character

Type

boolean

$is_right_to_left

$is_right_to_left : boolean

True if it is a right to left character

Type

boolean

$ltr

$ltr : boolean

True if it is a left to right character

Type

boolean

$is_ltr

$is_ltr : boolean

True if it is a left to right character

Type

boolean

$left_to_right

$left_to_right : boolean

True if it is a left to right character

Type

boolean

$is_left_to_right

$is_left_to_right : boolean

True if it is a left to right character

Type

boolean

$

$ : \Malenki\Bah\A

Collection of all characters of the same unicode block of current character.

Type

\Malenki\Bah\A

$value

$value : mixed

Type

mixed — Primitive value

$arr_blocks

$arr_blocks : 

Type

$col_bytes

$col_bytes : 

Type

$bool_is_surrogate

$bool_is_surrogate : boolean

Store whether the current character is surrogate or not.

This exists only to avoid PHP bug with preg_match() function and \p{Cs} pattern.

Type

boolean

Methods

__get()

__get( $name) : mixed

Magic getters engine.

By default, return internal O::$value attribute.

Parameters

$name

Returns

mixed

__toString()

__toString() : string

Converts character as string into string context.

This return internal value of the character, as a string, while it is used into string context.

Example:

$c = new C('a');
echo $c; // 'a'

Returns

string

__construct()

__construct(mixed $char)

Instanciates new character.

Creates new character object using 3 different ways.

You can instanciate it using:

  • a \Malenki\Bah\N object. In this case, given object is read to be the UTF-8 code point of the character. So, The Bah Number must be in [0, 0x10FFFF] range to be valid.
  • a string-like value having more than one characters must be an HTML entity
  • a single char string-like.

Examples:

// Unicode code point way
$n = new N(948);
$c = new C($n);
echo $c; //'δ'

// XML entity way
$c = new C('é');
echo $c; // 'é'

// direct way
$c = new C('z');
echo $c; // 'z'

Parameters

mixed $char

A string-like or \Malenki\Bah\N object

Throws

\InvalidArgumentException

If given Bah Number is not into the valid UTF-8 range.

\InvalidArgumentException

If given HTML entity is not valid.

\InvalidArgumentException

If given char is not valid UTF-8 char.

encodings()

encodings() : \Malenki\Bah\A

Lists all available encodings.

List all available encodings, as collection of \Malenki\Bah\S objects.

Returns

\Malenki\Bah\A

mustBeStringOrScalar()

mustBeStringOrScalar(mixed $arg, string $arg_name) : void

Checks whether given value is string-like or scalar type.

Value must be of string-like type (string or object having __toString() method) or a basic scalar type.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeString()

mustBeString(mixed $arg, string $arg_name) : void

Checks whether given value is string-like type.

A string-like value is string or object having __toString() method.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeInteger()

mustBeInteger(mixed $arg, string $arg_name) : void

Checks whether given value is integer-like type.

An integer-like value is integer or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeFloat()

mustBeFloat(mixed $arg, string $arg_name) : void

Checks whether given value is float-like type.

A float-like value is float or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeDouble()

mustBeDouble(mixed $arg, string $arg_name) : void

Checks whether given value is double-like type.

A double-like value is string or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeNumeric()

mustBeNumeric(mixed $arg, string $arg_name) : void

Checks whether given value is numeric-like type.

A numeric-like value is numeric (integer, float or double) or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeArray()

mustBeArray(mixed $arg, string $arg_name) : void

Checks whether given value is an array-like type.

A array-like value is an array or \Malenki\Bah\A object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeHash()

mustBeHash(mixed $arg, string $arg_name) : void

Checks whether given value is a hash-like type.

A hash-like value is an array having named-index or \Malenki\Bah\H object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeArrayOrHash()

mustBeArrayOrHash(mixed $arg, string $arg_name) : void

Checks whether given value is an array-like or hash-like type.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeCallable()

mustBeCallable(mixed $arg, mixed $arg_name) : void

Checks whether the given argument is callable.

This is usefull to test is an argument can be call as a function. If this argument is not callable, then this raises an \InvalidArgumentException.

Parameters

mixed $arg

The value to test

mixed $arg_name

Optional name of the value, used into error message

Throws

\InvalidArgumentException

If arg is not callable

_string()

_string() : string

Casts current character to primitive string type.

Casts current character as simple string PHP primitive type.

Example:

$c = new C('f');
var_dump($c->string); // string(1)

Returns

string

_str()

_str() : string

Casts current character to primitive string type (Alias).

Returns

string

_integer()

_integer() : integer

Casts current character to integer primitive type.

If current character is digit form 0 to 9, then it can be casted to integer php primitive type.

Example:

$c = new C('5');
var_dump($c->integer); // int(5)

Throws

\RuntimeException

If current character is not numeric.

Returns

integer

_int()

_int() : integer

Casts current character to integer primitive type (Alias).

Throws

\RuntimeException

If current character is not numeric.

Returns

integer

_trans()

_trans() : \Malenki\Bah\S

Transliterate current character.

Current character is transliterated to \Malenki\Bah\S object.

Example:

$c = new C('ç');
echo $c->trans; // 'c'

Note: Returned object is not \Malenki\Bah\C object, but \Malenki\Bah\S object, because translierated character can give more than one new characters.

Throws

\RuntimeException

If Intl PHP extension is not available

\RuntimeException

If Intl is available, but PHP version is less than 5.4.0. Transliterating feature is available since PHP 5.4.0.

Returns

\Malenki\Bah\S

_upper()

_upper() : \Malenki\Bah\C

Transforms to uppercase.

Returns new character object translated to uppercase, if any. If no uppercase exists, returns same character.

Example:

$c = new C('œ');
echo $c->upper; // 'Œ'
$c = new C('9');
echo $c->upper; // '9'

Returns

\Malenki\Bah\C

_lower()

_lower() : \Malenki\Bah\C

Transforms to lowercase.

Returns new character object translated to lowercase, if any. If no lowercase exists, returns same character.

Example:

$c = new C('A');
echo $c->lower; // 'a'
$c = new C('9');
echo $c->lower; // '9'

Returns

\Malenki\Bah\C

_isLetter()

_isLetter() : boolean

Checks whether current character is a letter.

Checks if current character represents a letter, and only a letter.

Example:

$c = new C('5');
var_dump($c->is_letter); // false
$c = new C('r');
var_dump($c->is_letter); // true

Returns

boolean

_isDigit()

_isDigit() : boolean

Checks whether current character is a digit.

Checks if current character represents a digit, so, a value form 0 to 9.

Example:

$c = new C('5');
var_dump($c->is_digit); // true
$c = new C('r');
var_dump($c->is_digit); // false

Returns

boolean

_isControl()

_isControl()

_isFormat()

_isFormat()

_isUnassigned()

_isUnassigned()

_isPrivateUse()

_isPrivateUse() : boolean

Checks if character is for private use only.

Checks whether current character must be use only for private uses or not.

Some UTF-8 characters can be used as you want, for example to have custom identicon. An example of private use is FontAwesome.

Example:

$c = new C(new N(0xe62e));
var_dump($c->is_private_use); // true

Returns

boolean

_isSurrogate()

_isSurrogate()

_isMark()

_isMark()

_isSeparator()

_isSeparator() : boolean

Tests if character is separator.

Tests whether current character is a separator, like no-break-space, space, ideographic space and so on.

Example:

$c = new C(' ');
var_dump($c->is_separator); // true

$c = new C("\t");
var_dump($c->is_separator); // false

Returns

boolean

_isPunctuation()

_isPunctuation() : boolean

Tests if character is a punctuation.

Tests whether current character is punctuation or not, like comma, dot, parentethis and so on…

Examples:

$c = new C('.');
var_dump($c->is_punctuation); // true

$c = new C(',');
var_dump($c->is_punctuation); // true

$c = new C('…');
var_dump($c->is_punctuation); // true

$c = new C('–');
var_dump($c->is_punctuation); // true

$c = new C('。');
var_dump($c->is_punctuation); // true

$c = new C('【');
var_dump($c->is_punctuation); // true

Returns

boolean

_isSymbol()

_isSymbol() : boolean

Tests if character is a symbol.

Tests whether current character stands for a symbol.

Example:

$euro = new C('€');
$a = new C('a');
var_dump($euro->is_symbol); // true
var_dump($a->is_symbol); // false

Returns

boolean

_isLowerCase()

_isLowerCase() : boolean

Tests whether current character is in lower case.

This is runtime part of some magic getters to test whether current character is in lower case or not.

Example:

$c = new C('a');
var_dump($c->is_lower_case); // true
var_dump($c->is_lower); // true

$c = new C('A');
var_dump($c->is_lower_case); // false
var_dump($c->is_lower); // false

Note: Not to be confused with C::lower! This convert current character to another character into lower case.

Returns

boolean

_isLower()

_isLower() : boolean

Tests whether current character is in lower case (Alias).

Returns

boolean

_isUpperCase()

_isUpperCase() : boolean

Tests whether current character is in upper case.

If current characters can be in lower or uppercase, then this tests if current character is upper case.

Example:

$c = new C('À');
var_dump($c->is_upper_case); // true
var_dump($c->is_upper); // true

$c = new C('à');
var_dump($c->is_upper_case); // false
var_dump($c->is_upper); // false

Returns

boolean

_isUpper()

_isUpper() : boolean

Tests whether current character is in upper case (Alias).

Returns

boolean

_isAscii()

_isAscii() : boolean

Tests if current character is from ASCII set or not.

UTF-8 characters are compatible with ASCII characters. ASCII characters are defined into the range [0x0, 0x7F].

Example:

$c = new C('a');
var_dump($c->is_ascii); // true

$c = new C('œ');
var_dump($c->is_ascii); // false

Returns

boolean

_hasCase()

_hasCase() : boolean

Tests if character has other cases or not.

Tests whether the current character has other cases or not.

Example:

$c = new C('a');
var_dump($c->has_case); //  true
$c = new C('!');
var_dump($c->has_case); //  false

Returns

boolean

_block()

_block() : \Malenki\Bah\S

Gets unicode block’s name

Returns unicode block’s name of current characters as a \Malenki\Bah\S object.

Example:

$c = new C('a');
$c->block; // 'Basic Latin'

This methods is the runtime part of magic getter \Malenki\Bah\C::$block

Throws

\Exception

If current character is not into unicode block

Returns

\Malenki\Bah\S

_family()

_family() : \Malenki\Bah\A

For current character, gets all characters of its unicode block.

All characters of the same block of current character are returned into an \Malenki\Bah\A collection of \Malenki\Bah\C objects.

Example:

$c = new \Malenki\Bah\C(new N(0x2191));
echo $c->family->join(',');
// print '←,↑,→,↓,↔,↕,↖,↗,↘,↙,↚,↛,↜,↝,↞,↟,↠,↡,↢,↣,↤,↥,↦,↧,↨,↩,↪,↫,
// ↬,↭,↮,↯,↰,↱,↲,↳,↴,↵,↶,↷,↸,↹,↺,↻,↼,↽,↾,↿,⇀,⇁,⇂,⇃,⇄,⇅,⇆,⇇,⇈,⇉,⇊,⇋,
//⇌,⇍,⇎,⇏,⇐,⇑,⇒,⇓,⇔,⇕,⇖,⇗,⇘,⇙,⇚,⇛,⇜,⇝,⇞,⇟,⇠,⇡,⇢,⇣,⇤

This methods is the runtime part of magic getter \Malenki\Bah\C::$family

Throws

\Exception

If current character is not into unicode block

Returns

\Malenki\Bah\A

_unicode()

_unicode() : \Malenki\Bah\N

Get unicode code point for the current character.

Returns unicode code point of current character as \Malenki\Bah\N object, so you can deal with different numeric systems.

This is runtime part of magic getter having same name.

Example:

$c = new C('€');
echo $c->unicode; // '8364'
echo $c->unicode->bin; // '10000010101100'
echo $c->unicode->oct; // '20254'
echo $c->unicode->hex; // '20ac'

Note: To get UTF8 bytes, use C::$bytes instead.

$c = new C('€');
echo $c->bytes->join(', '); // 226, 130, 172

Returns

\Malenki\Bah\N

_rtl()

_rtl() : boolean

Checks if current character is RTL.

Checks whether current character is RTL, understand Right To Left, like you can see into Arabic or Hebrew language for examples (but other langauges exist too).

Example:

$c = new C('ش');
var_dump($c->rtl); // true
var_dump($c->is_rtl); // true
var_dump($c->is_right_to_left); // true
var_dump($c->right_to_left); // true

$c = new C('a');
var_dump($c->rtl); // false
var_dump($c->is_rtl); // false
var_dump($c->is_right_to_left); // false
var_dump($c->right_to_left); // false

Returns

boolean

_ltr()

_ltr() : boolean

Checks if current character is LTR.

Checks whether current character is LTR, understand Left To Right, like you can see into English, French, Dutch and many others.

This is the opposite of \Malenki\Bah\C::_rtl() method.

This method is runtime par of some magic getters, these have the same name as RTL version, but with left in place of right and vice versa ;-)

Example:

$c = new C('ش');
var_dump($c->ltr); // false
var_dump($c->is_ltr); // false
var_dump($c->left_to_right); // false
var_dump($c->is_left_to_right); // false

$c = new C('a');
var_dump($c->ltr); // true
var_dump($c->is_ltr); // true
var_dump($c->left_to_right); // true
var_dump($c->is_left_to_right); // true

Returns

boolean