Name: Anonymous 2010-06-05 0:56
Is there any script, preferably bash or Perl, that will convert normal ASCII ("deal") into wide-width latin ("deal")?
Thanks.
Thanks.
function ascii_to_wwlatin ($str)
{
$retval = '';
foreach (str_split($str) as $chr) {
$ord = ord($chr);
$retval .= $ord > 32 && $ord < 127 ?
html_entity_decode('' . ($ord + 65248) . ';', ENT_NOQUOTES, 'UTF-8') :
chr($ord);
}
return $retval;
}echo ascii_to_wwlatin('Hi, >>1. I\'m using PHP. DEAL with it!');
if ($_SERVER['argc'] == 1) {
echo "usage: php asc2wwl.php [ascii string]\n";
exit();
}
echo ascii_to_wwlatin($_SERVER['argv'][1]);
#!/usr/bin/perl -pl
use encoding utf8;
y/!-~/\x{ff01}-\x{ff5e}/;#!/usr/bin/perl -l40
use encoding utf8;
y/!-~/\x{ff01}-\x{ff5e}/ and print for @ARGV;
tr supports unicode, which is not the case on many systems. perl always supports unicode.
/* Copyright (c) 2009 Xarn
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#define __STDC_ISO_10646__ 200104L
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>
int main(void)
{
char *buffa = NULL;
unsigned int n;
if (setlocale(LC_CTYPE, "") == NULL) {
fprintf(stderr, "Locale not specified. Fix this.\n");
return 1;
}
while (getline(&buffa, &n, stdin) != -1) {
char *c;
for (c = buffa; *c; ++c)
printf("%lc", '!' <= *c && *c <= '~' ? *c + 0xfee0
: *c == ' ' ? 0x3000
: *c);
free(buffa);
buffa = NULL;
}
return 0;
}