StringScanner port from ruby