Коммит
c72022ee37
|
@ -1705,7 +1705,7 @@ LibraryManager.library = {
|
|||
if (nextC > 0) {
|
||||
var maxx = 1;
|
||||
if (nextC > formatIndex+1) {
|
||||
var sub = format.substring(formatIndex+1, nextC)
|
||||
var sub = format.substring(formatIndex+1, nextC);
|
||||
maxx = parseInt(sub);
|
||||
if (maxx != sub) maxx = 0;
|
||||
}
|
||||
|
@ -1723,6 +1723,53 @@ LibraryManager.library = {
|
|||
}
|
||||
}
|
||||
|
||||
// handle %[...]
|
||||
if (format[formatIndex] === '%' && format.indexOf('[', formatIndex+1) > 0) {
|
||||
var match = /\%([0-9]*)\[(\^)?(\]?[^\]]*)\]/.exec(format.substring(formatIndex));
|
||||
if (match) {
|
||||
var maxNumCharacters = parseInt(match[1]) || Infinity;
|
||||
var negateScanList = (match[2] === '^');
|
||||
var scanList = match[3];
|
||||
|
||||
// expand "middle" dashs into character sets
|
||||
var middleDashMatch;
|
||||
while ((middleDashMatch = /([^\-])\-([^\-])/.exec(scanList))) {
|
||||
var rangeStartCharCode = middleDashMatch[1].charCodeAt(0);
|
||||
var rangeEndCharCode = middleDashMatch[2].charCodeAt(0);
|
||||
for (var expanded = ''; rangeStartCharCode <= rangeEndCharCode; expanded += String.fromCharCode(rangeStartCharCode++));
|
||||
scanList = scanList.replace(middleDashMatch[1] + '-' + middleDashMatch[2], expanded);
|
||||
}
|
||||
|
||||
var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}};
|
||||
argIndex += Runtime.getAlignSize('void*', null, true);
|
||||
fields++;
|
||||
|
||||
for (var i = 0; i < maxNumCharacters; i++) {
|
||||
next = get();
|
||||
if (negateScanList) {
|
||||
if (scanList.indexOf(String.fromCharCode(next)) < 0) {
|
||||
{{{ makeSetValue('argPtr++', 0, 'next', 'i8') }}};
|
||||
} else {
|
||||
unget();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (scanList.indexOf(String.fromCharCode(next)) >= 0) {
|
||||
{{{ makeSetValue('argPtr++', 0, 'next', 'i8') }}};
|
||||
} else {
|
||||
unget();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write out null-terminating character
|
||||
{{{ makeSetValue('argPtr++', 0, '0', 'i8') }}};
|
||||
formatIndex += match[0].length;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// remove whitespace
|
||||
while (1) {
|
||||
next = get();
|
||||
|
|
|
@ -6908,6 +6908,29 @@ at function.:blag
|
|||
printf("%i\n", a);
|
||||
}
|
||||
|
||||
char buf1[100], buf2[100], buf3[100], buf4[100];
|
||||
|
||||
int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4);
|
||||
printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4);
|
||||
|
||||
numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2);
|
||||
printf("%d, %s, %s\n", numItems, buf1, buf2);
|
||||
|
||||
numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2);
|
||||
printf("%d, %s, %s\n", numItems, buf1, buf2);
|
||||
|
||||
numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2);
|
||||
printf("%d, %s, %s\n", numItems, buf1, buf2);
|
||||
|
||||
numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2);
|
||||
printf("%d, %s\n", numItems, buf1);
|
||||
|
||||
numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1);
|
||||
printf("%d, %s\n", numItems, buf1);
|
||||
|
||||
numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2);
|
||||
printf("%d, %s, %s\n", numItems, buf1, buf2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
@ -6915,7 +6938,14 @@ at function.:blag
|
|||
'1\n1499\n' +
|
||||
'5\n87,0.481565,0.059481,0,1\n' +
|
||||
'3\n-123,4294966531,-34\n' +
|
||||
'1\n')
|
||||
'1\n' +
|
||||
'4, level, 4, ref, 3\n' +
|
||||
'2, def, 456\n' +
|
||||
'2, 3-4, -ab\n' +
|
||||
'2, Hello, World\n' +
|
||||
'1, Hello\n' +
|
||||
'1, Java\n' +
|
||||
'2, [, ]')
|
||||
|
||||
def test_sscanf_2(self):
|
||||
# doubles
|
||||
|
|
Загрузка…
Ссылка в новой задаче