aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2015-01-23 22:29:55 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2015-01-23 22:29:55 +0100
commita99f380cadc731700aa79ffde8f9cefc7ecae808 (patch)
tree34df28909326b31851dfd35ca4734f70361783fc
parentda2d2d9b39133cac522592cf62511b58346b5546 (diff)
parent29ad2fe7cfcd39e987dc99f40d936a2e74664bf5 (diff)
downloadUstring-a99f380cadc731700aa79ffde8f9cefc7ecae808.zip
Ustring-a99f380cadc731700aa79ffde8f9cefc7ecae808.tar.gz
Ustring-a99f380cadc731700aa79ffde8f9cefc7ecae808.tar.bz2
Merge branch 'bins' into incoming
-rw-r--r--Bin/Fromcode.php123
-rw-r--r--Bin/Tocode.php123
2 files changed, 246 insertions, 0 deletions
diff --git a/Bin/Fromcode.php b/Bin/Fromcode.php
new file mode 100644
index 0000000..3c9cf72
--- /dev/null
+++ b/Bin/Fromcode.php
@@ -0,0 +1,123 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\String\Bin;
+
+use Hoa\Console;
+use Hoa\String;
+
+/**
+ * Class Hoa\String\Bin\Fromcode.
+ *
+ * Get a character from its code. Please, see Hoa\String\String::fromCode.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Fromcode extends Console\Dispatcher\Kit {
+
+ /**
+ * Options description.
+ *
+ * @var \Hoa\String\Bin\Fromcode array
+ */
+ protected $options = [
+ ['base', Console\GetOption::REQUIRED_ARGUMENT, 'b'],
+ ['help', Console\GetOption::NO_ARGUMENT, 'h'],
+ ['help', Console\GetOption::NO_ARGUMENT, '?']
+ ];
+
+
+
+ /**
+ * The entry method.
+ *
+ * @access public
+ * @return int
+ */
+ public function main ( ) {
+
+ $base = 16;
+
+ while(false !== $c = $this->getOption($v)) switch($c) {
+
+ case 'b':
+ $base = intval($v);
+ break;
+
+ case '__ambiguous':
+ $this->resolveOptionAmbiguity($v);
+ break;
+
+ case 'h':
+ case '?':
+ default:
+ return $this->usage();
+ break;
+ }
+
+ $this->parser->listInputs($code);
+
+ $char = String::fromCode(base_convert($code, $base, 10));
+
+ echo $char;
+
+ return;
+ }
+
+ /**
+ * The command usage.
+ *
+ * @access public
+ * @return int
+ */
+ public function usage ( ) {
+
+ echo 'Usage : string:fromcode <char>', "\n",
+ 'Options :', "\n",
+ $this->makeUsageOptionsList([
+ 'b' => 'Specify the base of the code (16 by default).',
+ 'help' => 'This help.'
+ ]), "\n";
+
+ return;
+ }
+}
+
+__halt_compiler();
+Get a character from its code.
diff --git a/Bin/Tocode.php b/Bin/Tocode.php
new file mode 100644
index 0000000..1c20116
--- /dev/null
+++ b/Bin/Tocode.php
@@ -0,0 +1,123 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\String\Bin;
+
+use Hoa\Console;
+use Hoa\String;
+
+/**
+ * Class Hoa\String\Bin\Tocode.
+ *
+ * Transform a character into its code. Please, see Hoa\String\String::toCode.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Tocode extends Console\Dispatcher\Kit {
+
+ /**
+ * Options description.
+ *
+ * @var \Hoa\String\Bin\Tocode array
+ */
+ protected $options = [
+ ['base', Console\GetOption::REQUIRED_ARGUMENT, 'b'],
+ ['help', Console\GetOption::NO_ARGUMENT, 'h'],
+ ['help', Console\GetOption::NO_ARGUMENT, '?']
+ ];
+
+
+
+ /**
+ * The entry method.
+ *
+ * @access public
+ * @return int
+ */
+ public function main ( ) {
+
+ $base = 16;
+
+ while(false !== $c = $this->getOption($v)) switch($c) {
+
+ case 'b':
+ $base = intval($v);
+ break;
+
+ case '__ambiguous':
+ $this->resolveOptionAmbiguity($v);
+ break;
+
+ case 'h':
+ case '?':
+ default:
+ return $this->usage();
+ break;
+ }
+
+ $this->parser->listInputs($char);
+
+ $code = base_convert((string) String::toCode($char), 10, $base);
+
+ echo $code, "\n";
+
+ return;
+ }
+
+ /**
+ * The command usage.
+ *
+ * @access public
+ * @return int
+ */
+ public function usage ( ) {
+
+ echo 'Usage : string:tocode <char>', "\n",
+ 'Options :', "\n",
+ $this->makeUsageOptionsList([
+ 'b' => 'Get the code in a specific base (16 by default).',
+ 'help' => 'This help.'
+ ]), "\n";
+
+ return;
+ }
+}
+
+__halt_compiler();
+Transform a character into its code.