Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

StrGetTokens の研究

上記のような記事を見つけたので、id:satob:20080225:p2 に書いた InstallShield のビルトイン関数 StrGetTokens*1 と普通のsplitの挙動を比較して、StrGetTokens が如何に変態か確かめてみる。

Ruby
$ irb
irb(main):001:0> ",a,b,c".split(",")
=> ["", "a", "b", "c"]
Perl
$ perl -MData::Dumper -MTerm::ReadLine -d -e1

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(-e:1):   1
  DB<1> p Dumper(split(",", ",a,b,c"))
$VAR1 = '';
$VAR2 = 'a';
$VAR3 = 'b';
$VAR4 = 'c';
Python
$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ",a,,b,c".split(",")
['', 'a', '', 'b', 'c']
JavaScript
$ js
Rhino 1.6 release 7 2008 10 14
js> ",a,b,c".split(",").toSource()
["", "a", "b", "c"]
Emacs
(split-string ",a,b,c" ",")
("" "a" "b" "c")
結論

StrGetTokensはマジ変態。