Hoa central
Tocode.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($char);
94 
95  $code = base_convert((string) Ustring::toCode($char), 10, $base);
96 
97  echo $code, "\n";
98 
99  return;
100  }
101 
107  public function usage()
108  {
109  echo
110  'Usage : string:tocode <char>', "\n",
111  'Options :', "\n",
112  $this->makeUsageOptionsList([
113  'b' => 'Get the code in a specific base (16 by default).',
114  'help' => 'This help.'
115  ]), "\n";
116 
117  return;
118  }
119 }
120 
121 __halt_compiler();
122 Transform a character into its code.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
static toCode($char)
Definition: Ustring.php:943
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190