Hoa central
Fromcode.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Ustring\Bin;
38 
39 use Hoa\Console;
40 use Hoa\Ustring;
41 
51 {
57  protected $options = [
59  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
60  ['help', Console\GetOption::NO_ARGUMENT, '?']
61  ];
62 
63 
64 
70  public function main()
71  {
72  $base = 16;
73 
74  while (false !== $c = $this->getOption($v)) {
75  switch ($c) {
76  case 'b':
77  $base = intval($v);
78 
79  break;
80 
81  case '__ambiguous':
82  $this->resolveOptionAmbiguity($v);
83 
84  break;
85 
86  case 'h':
87  case '?':
88  default:
89  return $this->usage();
90  }
91  }
92 
93  $this->parser->listInputs($code);
94 
95  $char = Ustring::fromCode(base_convert($code, $base, 10));
96 
97  echo $char;
98 
99  return;
100  }
101 
107  public function usage()
108  {
109  echo
110  'Usage : string:fromcode <char>', "\n",
111  'Options :', "\n",
112  $this->makeUsageOptionsList([
113  'b' => 'Specify the base of the code (16 by default).',
114  'help' => 'This help.'
115  ]), "\n";
116 
117  return;
118  }
119 }
120 
121 __halt_compiler();
122 Get a character from its code.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
static fromCode($code)
Definition: Ustring.php:928
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190