Wide-Latin bash script?
1
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.
2
Name:
Anonymous
2010-06-05 0:58
Yes, there is.
3
Name:
Anonymous
2010-06-05 1:18
Please link?
4
Name:
Anonymous
2010-06-05 1:23
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!');
Hi, >>1. I'm using PHP. DEAL with it!
5
Name:
Anonymous
2010-06-05 1:44
>>4
That is pretty cool. Thanks. Would be better if I could pass the args to it -> so I can /exec it in irssi.
6
Name:
Anonymous
2010-06-05 1:58
>>5
something like this?
if ($_SERVER['argc'] == 1) {
echo "usage: php asc2wwl.php [ascii string]\n";
exit();
}
echo ascii_to_wwlatin($_SERVER['argv'][1]);
7
Name:
Anonymous
2010-06-05 2:07
>>6
Sweet.
I get:
>06:07:01 No entry for terminal type "tty";
>06:07:01 using dumb terminal settings.
in irssi when I exec it. What might be the cause?
8
Name:
Anonymous
2010-06-05 4:26
>>7
What might be the cause?
Not making proper Shii
t chan quotes would probably be it.
9
Name:
Anonymous
2010-06-05 4:27
>>8
Please don't give me that, I most often frequent the image-boards.
Do you know why I would get that PHP error?
10
Name:
Anonymous
2010-06-05 4:30
#!/usr/bin/perl -pl
use encoding utf8;
y/!-~/\x{ff01}-\x{ff5e}/;
and for
>>5 :
#!/usr/bin/perl -l40
use encoding utf8;
y/!-~/\x{ff01}-\x{ff5e}/ and print for @ARGV;
11
Name:
Anonymous
2010-06-05 4:32
12
Name:
Anonymous
2010-06-05 4:42
>>10
Thanks /expert programmer/.
13
Name:
Anonymous
2010-06-05 5:38
i wrote a c program to do it
14
Name:
Anonymous
2010-06-05 7:52
>>9
I most often frequent the image-boards.
>>10
Why are you helping him?
15
Name:
Anonymous
2010-06-05 8:07
>>14
perl one-liners are a lot less helpful than the other posts in this thread.
16
Name:
Anonymous
2010-06-05 8:09
>>15
Yeah, in that they do the job in more than one line. Unhelpful bastards.
17
Name:
Anonymous
2010-06-05 8:14
>>16
i meant ones like
>>8,11 .
18
Name:
Anonymous
2010-06-05 11:23
>>17
Using PHP is a legitimate problem.
19
Name:
Anonymous
2010-06-05 11:30
Why do you need any of this? Learn to use a shell.
$ echo hax my anus | tr \ -~ !-~
hax my anus
20
Name:
Anonymous
2010-06-05 13:44
21
Name:
Anonymous
2010-06-05 13:52
>>20
DEAL WITH IT!
22
Name:
Anonymous
2010-06-05 14:00
>>19
More like
$ echo hax my anus | tr \ -~ !-~
Ľ��������
23
Name:
Anonymous
2010-06-05 14:15
AA A A A A A A A A A A A A A A A A A A A A A A A
24
Name:
Anonymous
2010-06-05 14:16
AA A A A A A A A A A A A A A A A A A A A A AAAAAAAAAAAAAAAAAAAAAAAAA A AAAAAAAAAAAAAAAAAAAAAAAAA
25
Name:
Anonymous
2010-06-05 14:32
>>19
that only works if your
tr supports unicode, which is not the case on many systems. perl always supports unicode.
26
Name:
Anonymous
2010-06-05 14:41
bump
27
Name:
Anonymous
2010-06-05 15:04
>>25
$ echo hax my anus | perl -pe 'tr/[ -~]/[!-~]/;'
����������
Goddamn liar.
Meanwhile,
Xarn 's program works fine:
$ echo hax my anus | fullwidth
hax my anus
28
Name:
Anonymous
2010-06-05 15:27
For the record:
/* 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;
}
29
Name:
Anonymous
2010-06-05 15:27
What is wrong with just typing with wide characters? You don’t need a script for it.
30
Name:
FrozenVoid⤆
2010-06-05 16:20
31
Name:
Anonymous
2010-06-05 16:34
>>30
If you don't even know how keyboard layouts are set, maybe you should ask in
/g/ .
32
Name:
Anonymous
2010-06-05 16:36
>>30
Full−width Romaji mode
!
33
Name:
Anonymous
2010-06-05 16:39
>>30
Why would you do something that doesn’t preserve screen real estate?
34
Name:
Anonymous
2010-06-05 17:27
>>33
doesn’t
You fail it, don't you?
35
Name:
Anonymous
2010-06-05 17:29
>>32
Oh snap motherfucker! This is awesome! :)
36
Name:
Anonymous
2010-06-05 17:36
>>35
You failed it again, >>33-san. Or perhaps I Have Beet Rolled .
37
Name:
Anonymous
2010-06-05 17:49
This thread is an abomination. Have we really sunk so low as to be amused by simple functionality?
38
Name:
sorry
2010-06-05 18:10
ifeelkindofbadaboutthat:(
39
Name:
Anonymous
2010-06-05 18:38
>>37
Just like every tripcode thread has to drown in idiots testing their tripcodes,
every thread that allows people to produce output they can post will be flooded with that. Even if most of them never figure out how to do it properly.
40
Name:
Anonymous
2010-06-05 18:42
hey guys am I doing it right?
41
Name:
Anonymous
2010-06-05 19:14
>>39
You mean like
http://harry.lu/mty/ ?
It does not work on the text-boards, only the image-boards.
42
Name:
Anonymous
2010-06-05 19:17
>>41
I don't think you're as good at reading posts as you think you are.
43
Name:
Anonymous
2010-06-05 19:22
>>42
|tripcode thread
|links to a tripcode producing program
I think I read it quite fine.
44
Name:
Anonymous
2010-06-05 19:27
>>43
|
How utterly unsurprising.
45
Name:
Anonymous
2010-06-05 19:40
| How utterly unsurprising.
This is more like it.
46
Name:
Anonymous
2010-06-05 19:44
>>27
of course it doesn't work if you intentionally write broken code.
use encoding utf8;
47
Name:
Anonymous
2010-06-05 20:47
>>46
Why, in this day and age, is any program
not utf8 by default?
48
Name:
Anonymous
2010-06-06 0:02
>>47
because not every program needs a bunch of bullshit code to handle a variable-length encoding.
49
Name:
Anonymous
2010-06-06 15:49
Shocking, not nearly enough “Toy language” implementations. Here is my overly-engineered Scheme version
#!/usr/bin/env scheme-script
; Hey Emacs!, This is a -*- Scheme -*- file
;;; fullwidth.ss
; Takes n command line arguments, and returns n lines with each argument
; string converted to be fullwidth
; Example:
; fullwidth "can i play with magic?"
; => can i play with magic?
(import (rnrs) (only (srfi :13) string-map))
; figure out the offset
; notice that the first 'a' is fullwidth
(define offset (- (char->integer #\a)
(char->integer #\a)))
(define (char+ char int)
(integer->char (+ int (char->integer char))))
(define fullwidth-symbols
; various other fullwidth symbols according to
; the unicode standard
'((#\x00A2 . #\xFFE0)
(#\x00A3 . #\xFFE1)
(#\x00AC . #\xFFE2)
(#\x00AF . #\xFFE3)
(#\x00A6 . #\xFFE4)
(#\x00A5 . #\xFFE5)
(#\x20A9 . #\xFFE6)))
(define (char-fullwidth x)
(cond ((char=? x #\space)
#\ ) ;special case for fullwidth space
((char<=? #\! x #\~)
(char+ x offset))
((assoc x fullwidth-symbols) => cdr)
(else x)))
(define (string-fullwidth s)
(string-map char-fullwidth s))
(define (main)
(let ((argv (cdr (command-line))))
(for-each (lambda (x)
(display (string-fullwidth x))
(newline))
argv)))
(main)
50
Name:
Anonymous
2010-06-06 16:11
>>49
Oh, fine.
module Main (main) where
import qualified System.IO.UTF8 as U
fullwidthConvert :: String -> String
fullwidthConvert = map fullwidthConvert'
where
fullwidthConvert' c = case lookup c table of
Just c' -> c'
Nothing -> c
where
table = zip (' ' : ['!'..'~'])
('\x3000' : ['\xff01'..'\xff5e'])
main :: IO ()
main = U.getContents >>= U.putStr . fullwidthConvert
51
Name:
Anonymous
2010-06-06 16:19
>>47
because some people don't care about gookspeak
52
Name:
Anonymous
2010-06-06 17:35
: >wide ( str -- wide )
[ [ 32 126 between? ]
[ [ 32 = ] [ 65248 + ] [ 12288 ] smart-if* ]
smart-when ]
map ;
53
Name:
Anonymous
2010-06-06 17:43
54
Name:
Anonymous
2010-06-06 17:49
>>52
smart-if
Steve Jobs would be proud.
55
Name:
Anonymous
2010-06-06 19:24
>>53
Looks like Factor.
(It makes you write better code.)
56
Name:
Anonymous
2010-06-06 21:45
>>55
it is factor.
>>54
smart-if is what
if should be.
57
Name:
Anonymous
2010-06-06 21:51
58
Name:
Anonymous
2010-06-06 21:59
>>57
That's not even close to how ellipses work.
59
Name:
Anonymous
2010-06-06 22:30
60
Name:
Anonymous
2010-06-06 22:32
>>59
I lol'd for no reason, and now I feel kind of aborted about it :(
61
Name:
Anonymous
2010-06-07 5:12
>>52
that should be
: >wide ( str -- wide )
[ [ 32 126 between? ]
[ [ 32 > ] [ 65248 + ] [ 12288 ] smart-if* ]
smart-when ]
map ;
62
Name:
Anonymous
2010-07-01 11:46
# bump
import sys, string
if len(sys.argv) > 1:
orig = sys.argv[1]
else:
orig = raw_input("Input a string to convert: ")
new = str()
for i in orig:
if i == " ":
new = new + unichr(0x3000)
elif i in string.printable:
new = new + unichr(0xFEE0 + ord(i))
else:
new = new + i
print new
63
Name:
Anonymous
2010-07-01 13:00
FUCK YOUR MOTHER SIDEWAYS
64
Name:
Anonymous
2010-07-01 13:39
Why are people still posting shit after the C implementation was posted?
65
Name:
Anonymous
2010-07-01 13:49
>>64
* Why are people still posting shit after
Xarn 's implementation was posted?
66
Name:
Anonymous
2010-07-01 13:52
>>65
It didn't use Allegro or Python; I doubt that.
67
Name:
Anonymous
2010-07-01 13:53
68
Name:
Anonymous
2010-07-01 14:29
>>66
If you only know
Xarn from two of the challenge threads, maybe you aren't in any position to identify his code.
69
Name:
Anonymous
2010-07-01 14:34
>>67,68
I've read his blog, and that's where I got the information to write
>>66 . Go on, deny it.
70
Name:
Anonymous
2010-07-01 14:38
Isn't it great that the author of the code makes more difference than the code itself?
71
Name:
Anonymous
2010-07-01 14:39
>>52,56
How does
smart-if work in Factor?
72
Name:
Anonymous
2010-07-01 14:44
73
Name:
Anonymous
2010-07-01 14:50
What about my a dolt?
74
Name:
Anonymous
2010-07-01 14:58
>>70
Only if the author is
Xarn .
75
Name:
Anonymous
2010-07-01 14:59
76
Name:
Anonymous
2010-07-01 15:00
y helo thar lol full−width romanji indeed
−−−
Posted from my iMac
77
Name:
Anonymous
2010-07-01 16:01
It’ s ``romaji’’, not ``romanji’’,
you stupid ``馬鹿’’ (日本語 for ``Idiot’’)
Reference:
http://img257.imageshack.us/img257/7140/nippon.png
−−−
Sent from my Mac Pro
78
Name:
Anonymous
2010-07-01 16:29
y helo thar lol full−width jumanji indeed
79
Name:
Anonymous
2010-07-01 17:16
Polecat kebabs
80
Name:
Anonymous
2010-07-01 17:24
Ok, I'll have to resort to this:
>>52,56
How does smart-if work in Factor?
81
Name:
Anonymous
2010-07-01 17:34
>>80
By employing best scalable practices。
82
Name:
Anonymous
2010-07-01 18:58
83
Name:
Anonymous
2010-07-01 19:01
>>82
Nonsense. Nothing useful is written in factor.
84
Name:
Anonymous
2010-07-01 19:06
>>83
sure, if you don't consider a good x86 assembler and a web framework that doesn't suck to be useful.
85
Name:
Anonymous
2010-07-01 19:10
x86 assembler
None I have used (or ever will) is written in factor.
web framework
I don't care what you write it in, that's not useful.
86
Name:
Anonymous
2010-07-01 19:19
x86 GET
87
Name:
Anonymous
2010-07-01 19:28
>>85
i suppose you also think gcc is the only c compiler that's useful because it's the only one you've ever used.
88
Name:
Anonymous
2010-07-01 19:34
>>84
Can you point me to this x86 assembler? I'd like to see it.
89
Name:
Anonymous
2010-07-01 19:37
>>87
Whoa, when did I invent time travel?
90
Name:
Anonymous
2010-07-01 19:37
91
Name:
Anonymous
2010-07-01 19:38
92
Name:
Anonymous
2010-07-03 17:11
>>64
It was incomplete, the only implementation that covered all of the fullwidth codepoints was the Scheme version.
94
Name:
Anonymous
2010-12-24 9:22