~ubuntu-branches/ubuntu/raring/parrot/raring-proposed

« back to all changes in this revision

Viewing changes to src/pmc/string.pmc

  • Committer: Bazaar Package Importer
  • Author(s): Allison Randal
  • Date: 2011-07-30 18:45:03 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110730184503-34d4mprtfx6pt5h3
Tags: 3.6.0-1
* New upstream release
* debian/watch:
  - Modified regular expression to capture numbered directory name
    (patch from Dominique Dumont).
* debian/rules:
  - Split build-arch and build-indep, resolving lintian warning.
  - Update path to pbc_disassemble for manpage generation (patch
    from Dominique Dumont).
* debian/patches:
  - Added patch 02_fix_perl_interpreter_path.patch, resolving
    lintian warnings.
* debian/control:
  - Added DM-Upload-Allowed field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
345
345
 
346
346
/*
347
347
 
348
 
=item C<void substr(INTVAL offset, INTVAL length, PMC *dest)>
349
 
 
350
 
Extracts the substring starting at C<offset>, with size
351
 
C<length>, and places it in C<dest>.
352
 
 
353
 
=cut
354
 
 
355
 
*/
356
 
    VTABLE void substr(INTVAL offset, INTVAL length, PMC *dest) {
357
 
        STRING *str_val, *s2;
358
 
        GET_ATTR_str_val(INTERP, SELF, str_val);
359
 
        s2 = STRING_substr(INTERP, str_val, offset, length);
360
 
        VTABLE_set_string_native(INTERP, dest, s2);
361
 
    }
362
 
 
363
 
/*
364
 
 
365
 
=item C<STRING *substr_str(INTVAL offset, INTVAL length)>
 
348
=item C<STRING *substr(INTVAL offset, INTVAL length)>
366
349
 
367
350
Extracts the substring starting at C<offset>, with size
368
351
C<length>, and returns it.
370
353
=cut
371
354
 
372
355
*/
373
 
    VTABLE STRING *substr_str(INTVAL offset, INTVAL length) {
 
356
    VTABLE STRING *substr(INTVAL offset, INTVAL length) {
374
357
        STRING *str_val;
375
358
        GET_ATTR_str_val(INTERP, SELF, str_val);
376
359
        return STRING_substr(INTERP, str_val, offset, length);
701
684
 
702
685
=item C<INTEGER is_integer(STRING *src)>
703
686
 
704
 
Checks if the ascii STRING C<str> is just an integer.
 
687
Checks if the STRING C<str> is just an integer. Accepts only '0'-'9'
 
688
characters, other digit representations aren't allowed.
705
689
 
706
690
=cut
707
691
 
709
693
 
710
694
    METHOD is_integer(STRING *src) {
711
695
        const INTVAL   len = Parrot_str_length(INTERP, src);
712
 
        const char *p;
713
696
 
714
697
        if (!len)
715
698
            RETURN(INTVAL 0);
716
699
 
717
 
        if (STRING_max_bytes_per_codepoint(src) != 1)
718
 
            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_ENCODING,
719
 
                "Can't is_integer non fixed_8");
720
 
 
721
 
        p = src->strstart;
722
 
        if (p[0] == '-' || p[0] == '+' || (p[0] >= '0' && p[0] <= '9')) {
723
 
            int i;
724
 
            for (i = 1; i < len; ++i)
725
 
                if (p[i] < '0' || p[i] > '9')
726
 
                    RETURN(INTVAL 0);
727
 
 
 
700
        if (STRING_max_bytes_per_codepoint(src) == 1) {
 
701
            const char *p = src->strstart;
 
702
            if (p[0] == '-' || p[0] == '+' || (p[0] >= '0' && p[0] <= '9')) {
 
703
                int i;
 
704
                for (i = 1; i < len; ++i)
 
705
                    if (p[i] < '0' || p[i] > '9')
 
706
                        RETURN(INTVAL 0);
 
707
 
 
708
                RETURN(INTVAL 1);
 
709
            }
 
710
            else
 
711
                RETURN(INTVAL 0);
 
712
        }
 
713
        else {
 
714
            String_iter iter;
 
715
            UINTVAL c;
 
716
            INTVAL i = 0;
 
717
            STRING_ITER_INIT(interp, &iter);
 
718
            c = STRING_iter_get_and_advance(interp, src, &iter);
 
719
            if ((c == '-' && len < 2) || c < '0' || c > '9')
 
720
                    RETURN(INTVAL 0);
 
721
            ++i;
 
722
            for (; i < len; ++i) {
 
723
                c = STRING_iter_get_and_advance(interp, src, &iter);
 
724
                if (c < '0' || c > '9')
 
725
                    RETURN(INTVAL 0);
 
726
            }
728
727
            RETURN(INTVAL 1);
729
728
        }
730
 
        else
731
 
            RETURN(INTVAL 0);
732
729
    }
733
730
 
734
731
    VTABLE PMC *share_ro() {