Slide 17
Slide 17 text
簡単なパーサ
簡単なパーサ
より引用
function parseHoge(target, position) {
if (target.substr(position, 4) === 'hoge') {
//
成功
return [true, 'hoge', position + 4];
} else {
//
失敗
return [false, null, position];
}
}
parseHoge('hoge', 0) // => [true, 'hoge', 4]
を返す
parseHoge('ahoge', 1) // => [true, 'hoge', 5]
を返す
parseHoge('aaa', 0) // => [false, null, 0]
を返す
http://blog.anatoo.jp/entry/2015/04/26/220026
17