|
236 | 236 |
|
237 | 237 | /***********************************************************************
|
238 | 238 | **
|
239 |
| -*/ REBFLG Check_Bit_Str(REBSER *bset, REBVAL *val, REBFLG uncased) |
| 239 | +*/ REBFLG Check_Bit_Str_Any(REBSER *bset, REBVAL *val, REBFLG uncased) |
240 | 240 | /*
|
241 | 241 | ** If uncased is TRUE, try to match either upper or lower case.
|
| 242 | +** Returns TRUE when first bit is found. |
242 | 243 | **
|
243 | 244 | ***********************************************************************/
|
244 | 245 | {
|
|
257 | 258 | return FALSE;
|
258 | 259 | }
|
259 | 260 |
|
| 261 | +/*********************************************************************** |
| 262 | +** |
| 263 | +*/ REBFLG Check_Bit_Str_All(REBSER *bset, REBVAL *val, REBFLG uncased) |
| 264 | +/* |
| 265 | +** If uncased is TRUE, try to match either upper or lower case. |
| 266 | +** Returns TRUE when all bits are found. |
| 267 | +** |
| 268 | +***********************************************************************/ |
| 269 | +{ |
| 270 | + REBCNT n = VAL_INDEX(val); |
| 271 | + |
| 272 | + if (VAL_BYTE_SIZE(val)) { |
| 273 | + REBYTE *bp = VAL_BIN(val); |
| 274 | + for (; n < VAL_TAIL(val); n++) |
| 275 | + if (!Check_Bit(bset, bp[n], uncased)) return FALSE; |
| 276 | + } |
| 277 | + else { |
| 278 | + REBUNI *up = VAL_UNI(val); |
| 279 | + for (; n < VAL_TAIL(val); n++) |
| 280 | + if (!Check_Bit(bset, up[n], uncased)) return FALSE; |
| 281 | + } |
| 282 | + return TRUE; |
| 283 | +} |
| 284 | + |
260 | 285 |
|
261 | 286 | /***********************************************************************
|
262 | 287 | **
|
|
414 | 439 |
|
415 | 440 | /***********************************************************************
|
416 | 441 | **
|
417 |
| -*/ REBFLG Check_Bits(REBSER *bset, REBVAL *val, REBFLG uncased) |
| 442 | +*/ REBFLG Check_Bits(REBSER *bset, REBVAL *val, REBFLG uncased, REBFLG any) |
418 | 443 | /*
|
419 | 444 | ** Check bits indicated by strings and chars and ranges.
|
420 | 445 | ** If uncased is TRUE, try to match either upper or lower case.
|
| 446 | +** If any is TRUE, than returns TRUE on first found bit. |
421 | 447 | **
|
422 | 448 | ***********************************************************************/
|
423 | 449 | {
|
|
430 | 456 | if (IS_INTEGER(val))
|
431 | 457 | return Check_Bit(bset, Int32s(val, 0), uncased);
|
432 | 458 |
|
433 |
| - if (ANY_BINSTR(val)) |
434 |
| - return Check_Bit_Str(bset, val, uncased); |
| 459 | + if (ANY_BINSTR(val)) { |
| 460 | + if (any) { |
| 461 | + return Check_Bit_Str_Any(bset, val, uncased); |
| 462 | + } |
| 463 | + else { |
| 464 | + return Check_Bit_Str_All(bset, val, uncased); |
| 465 | + } |
| 466 | + |
| 467 | + } |
435 | 468 |
|
436 | 469 | if (!ANY_BLOCK(val)) Trap_Type(val);
|
437 | 470 |
|
|
448 | 481 | n = VAL_CHAR(val);
|
449 | 482 | scan_bits:
|
450 | 483 | if (n < c) Trap1(RE_PAST_END, val);
|
451 |
| - for (; c <= n; c++) |
452 |
| - if (Check_Bit(bset, c, uncased)) goto found; |
| 484 | + if (any) { |
| 485 | + for (; c <= n; c++) |
| 486 | + if (Check_Bit(bset, c, uncased)) return TRUE; |
| 487 | + } |
| 488 | + else { |
| 489 | + for (; c <= n; c++) |
| 490 | + if (!Check_Bit(bset, c, uncased)) return FALSE; |
| 491 | + goto bit_found; |
| 492 | + } |
453 | 493 | } else Trap_Arg(val);
|
454 | 494 | }
|
455 | 495 | else
|
456 |
| - if (Check_Bit(bset, c, uncased)) goto found; |
| 496 | + if (Check_Bit(bset, c, uncased)) goto bit_found; |
457 | 497 | break;
|
458 | 498 |
|
459 | 499 | case REB_INTEGER:
|
460 | 500 | n = Int32s(val, 0);
|
461 |
| - if (n > 0xffff) return 0; |
| 501 | + if (n > 0xffff) goto bit_not_found; |
462 | 502 | if (IS_SAME_WORD(val + 1, SYM__)) {
|
463 | 503 | c = n;
|
464 | 504 | val += 2;
|
|
468 | 508 | } else Trap_Arg(val);
|
469 | 509 | }
|
470 | 510 | else
|
471 |
| - if (Check_Bit(bset, n, uncased)) goto found; |
| 511 | + if (Check_Bit(bset, n, uncased)) goto bit_found; |
472 | 512 | break;
|
473 | 513 |
|
474 | 514 | case REB_BINARY:
|
|
478 | 518 | case REB_URL:
|
479 | 519 | case REB_TAG:
|
480 | 520 | // case REB_ISSUE:
|
481 |
| - if (Check_Bit_Str(bset, val, uncased)) goto found; |
| 521 | + if (any) { |
| 522 | + if (Check_Bit_Str_Any(bset, val, uncased)) goto bit_found; |
| 523 | + } |
| 524 | + else { |
| 525 | + if (Check_Bit_Str_All(bset, val, uncased)) goto bit_found; |
| 526 | + } |
482 | 527 | break;
|
483 | 528 |
|
484 | 529 | default:
|
485 | 530 | Trap_Type(val);
|
486 | 531 | }
|
| 532 | + bit_not_found: |
| 533 | + if (!any) |
| 534 | + return FALSE; |
| 535 | + continue; |
| 536 | + bit_found: |
| 537 | + if (any) { |
| 538 | + return TRUE; |
| 539 | + } |
487 | 540 | }
|
488 |
| - return FALSE; |
489 |
| - |
490 |
| -found: |
491 | 541 | return TRUE;
|
492 | 542 | }
|
493 | 543 |
|
|
511 | 561 | }
|
512 | 562 | return PE_NONE;
|
513 | 563 | #else
|
514 |
| - SET_LOGIC(pvs->store, Check_Bits(ser, pvs->select, 0)); |
| 564 | + SET_LOGIC(pvs->store, Check_Bits(ser, pvs->select, 0, FALSE)); |
515 | 565 | return PE_USE;
|
516 | 566 | #endif
|
517 | 567 | }
|
|
600 | 650 |
|
601 | 651 | case A_PICK:
|
602 | 652 | case A_FIND:
|
603 |
| - if (!Check_Bits(VAL_SERIES(value), arg,(IS_CHAR(arg) && action == A_FIND && !D_REF(ARG_FIND_CASE)) )) |
| 653 | + if (!Check_Bits(VAL_SERIES(value), arg,(IS_CHAR(arg) && action == A_FIND && !D_REF(ARG_FIND_CASE)), (action == A_FIND && D_REF(ARG_FIND_ANY)))) |
604 | 654 | #ifdef PICK_BITSET_AS_NONE
|
605 | 655 | return R_NONE;
|
606 | 656 | #else
|
|
0 commit comments