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

« back to all changes in this revision

Viewing changes to src/string/api.c

  • 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:
31
31
/* for parrot/interpreter.h */
32
32
STRING *STRINGNULL;
33
33
 
34
 
#define DEBUG_HASH_SEED 0
35
 
 
36
34
#define nonnull_encoding_name(s) (s) ? (s)->encoding->name : "null string"
37
35
#define ASSERT_STRING_SANITY(s) \
38
36
    PARROT_ASSERT((s)->encoding); \
45
43
 
46
44
PARROT_WARN_UNUSED_RESULT
47
45
PARROT_PURE_FUNCTION
48
 
static INTVAL string_max_bytes(SHIM_INTERP,
 
46
static INTVAL string_max_bytes(PARROT_INTERP,
49
47
    ARGIN(const STRING *s),
50
48
    UINTVAL nchars)
51
49
        __attribute__nonnull__(2);
129
127
 
130
128
    /* interp is initialized from zeroed memory, so this is fine */
131
129
    else if (interp->hash_seed == 0) {
132
 
        /* TT #64 - use an entropy source once available */
133
 
        Parrot_util_srand(Parrot_intval_time());
134
 
        interp->hash_seed = Parrot_util_uint_rand(0);
135
 
#if DEBUG_HASH_SEED
136
 
        fprintf(stderr, "HASH SEED: %x\n", interp->hash_seed);
137
 
#endif
 
130
        interp->hash_seed = Parrot_get_entropy(interp);
138
131
    }
139
132
 
140
133
    /* initialize the constant string table */
339
332
*/
340
333
 
341
334
PARROT_WARN_UNUSED_RESULT
342
 
PARROT_CAN_RETURN_NULL
 
335
PARROT_CANNOT_RETURN_NULL
343
336
STRING *
344
337
Parrot_str_clone(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
345
338
{
381
374
*/
382
375
 
383
376
PARROT_EXPORT
384
 
PARROT_CAN_RETURN_NULL
 
377
PARROT_CANNOT_RETURN_NULL
385
378
PARROT_WARN_UNUSED_RESULT
386
379
STRING *
387
380
Parrot_str_copy(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
443
436
*/
444
437
 
445
438
PARROT_EXPORT
446
 
PARROT_CAN_RETURN_NULL
 
439
PARROT_CANNOT_RETURN_NULL
447
440
STRING *
448
441
Parrot_str_concat(PARROT_INTERP, ARGIN_NULLOK(const STRING *a),
449
442
            ARGIN_NULLOK(const STRING *b))
749
742
 
750
743
PARROT_EXPORT
751
744
PARROT_CAN_RETURN_NULL
 
745
PARROT_WARN_UNUSED_RESULT
752
746
char *
753
747
Parrot_str_to_platform_cstring(PARROT_INTERP, ARGIN(const STRING *s))
754
748
{
1060
1054
    ARGIN(const String_iter *l), ARGIN_NULLOK(const String_iter *r))
1061
1055
{
1062
1056
    ASSERT_ARGS(Parrot_str_iter_substr)
1063
 
    STRING *dest = Parrot_str_copy(interp, str);
 
1057
    STRING * const dest = Parrot_str_copy(interp, str);
1064
1058
 
1065
1059
    dest->strstart = (char *)dest->strstart + l->bytepos;
1066
1060
 
1164
1158
*/
1165
1159
 
1166
1160
PARROT_EXPORT
1167
 
PARROT_CAN_RETURN_NULL
 
1161
PARROT_CANNOT_RETURN_NULL
1168
1162
PARROT_WARN_UNUSED_RESULT
1169
1163
STRING *
1170
1164
Parrot_str_replace(PARROT_INTERP, ARGIN(const STRING *src),
2367
2361
*/
2368
2362
 
2369
2363
PARROT_EXPORT
2370
 
PARROT_CAN_RETURN_NULL
 
2364
PARROT_CANNOT_RETURN_NULL
2371
2365
STRING *
2372
2366
Parrot_str_escape(PARROT_INTERP, ARGIN_NULLOK(const STRING *src))
2373
2367
{
2389
2383
*/
2390
2384
 
2391
2385
PARROT_EXPORT
2392
 
PARROT_CAN_RETURN_NULL
 
2386
PARROT_CANNOT_RETURN_NULL
2393
2387
STRING *
2394
2388
Parrot_str_escape_truncate(PARROT_INTERP,
2395
2389
        ARGIN_NULLOK(const STRING *src), UINTVAL limit)
2399
2393
    UINTVAL      i, len, charlen;
2400
2394
    String_iter  iter;
2401
2395
    char         hex_buf[16];
2402
 
    int          hex_len;
2403
2396
    char        *dp;
2404
2397
 
2405
2398
    if (STRING_IS_NULL(src))
2426
2419
 
2427
2420
    for (i = 0; len > 0; --len) {
2428
2421
        unsigned c = STRING_iter_get_and_advance(interp, src, &iter);
 
2422
        int hex_len;
 
2423
 
2429
2424
        if (c < 0x7f) {
2430
2425
            /* process ASCII chars */
2431
2426
            if (i >= charlen - 2) {
2995
2990
 
2996
2991
PARROT_EXPORT
2997
2992
PARROT_WARN_UNUSED_RESULT
2998
 
PARROT_CAN_RETURN_NULL
 
2993
PARROT_CANNOT_RETURN_NULL
2999
2994
STRING *
3000
2995
Parrot_str_compose(PARROT_INTERP, ARGIN_NULLOK(const STRING *src))
3001
2996
{
3002
2997
    ASSERT_ARGS(Parrot_str_compose)
3003
2998
 
3004
2999
    if (STRING_IS_NULL(src))
3005
 
        return NULL;
 
3000
        return STRINGNULL;
3006
3001
 
3007
 
    if (!src->strlen)
 
3002
    if (src->strlen == 0)
3008
3003
        return CONST_STRING(interp, "");
3009
3004
 
3010
3005
    return STRING_compose(interp, src);
3048
3043
        length   = Parrot_str_byte_length(interp, first);
3049
3044
        j_length = Parrot_str_byte_length(interp, j);
3050
3045
 
3051
 
        /* it's an approximiation, but it doesn't hurt */
 
3046
        /* it's an approximation, but it doesn't hurt */
3052
3047
        sb       = Parrot_pmc_new_init_int(interp, enum_class_StringBuilder,
3053
3048
                    (length + j_length) * count);
3054
3049
 
3055
3050
        VTABLE_push_string(interp, sb, first);
3056
3051
 
3057
3052
        for (i = 1; i < count; ++i) {
3058
 
            VTABLE_push_string(interp, sb, j);
3059
 
            VTABLE_push_string(interp, sb,
3060
 
                VTABLE_get_string_keyed_int(interp, ar, i));
 
3053
            STRING *part = VTABLE_get_string_keyed_int(interp, ar, i);
 
3054
            if (j_length)
 
3055
                VTABLE_push_string(interp, sb, j);
 
3056
 
 
3057
            if (part->strlen)
 
3058
                VTABLE_push_string(interp, sb, part);
3061
3059
        }
3062
3060
 
3063
3061
        return VTABLE_get_string(interp, sb);
3080
3078
 
3081
3079
PARROT_EXPORT
3082
3080
PARROT_WARN_UNUSED_RESULT
3083
 
PARROT_CAN_RETURN_NULL
 
3081
PARROT_CANNOT_RETURN_NULL
3084
3082
PMC*
3085
3083
Parrot_str_split(PARROT_INTERP,
3086
3084
    ARGIN_NULLOK(const STRING *delim), ARGIN_NULLOK(const STRING *str))