~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to regerror.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-05-16 12:37:06 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080516123706-r4llcdfd35aobrjv
Tags: 1.9.0.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.
* debian/control:
  - ruby1.9 pkg: moved rdoc1.9 suggestion to depends. (LP: #228345)

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
    p = "too big wide-char value"; break;
143
143
  case ONIGERR_TOO_LONG_WIDE_CHAR_VALUE:
144
144
    p = "too long wide-char value"; break;
145
 
  case ONIGERR_INVALID_WIDE_CHAR_VALUE:
146
 
    p = "invalid wide-char value"; break;
 
145
  case ONIGERR_INVALID_CODE_POINT_VALUE:
 
146
    p = "invalid code point value"; break;
147
147
  case ONIGERR_EMPTY_GROUP_NAME:
148
148
    p = "group name is empty"; break;
149
149
  case ONIGERR_INVALID_GROUP_NAME:
182
182
  return (UChar* )p;
183
183
}
184
184
 
 
185
static void sprint_byte(char* s, unsigned int v)
 
186
{
 
187
  sprintf(s, "%02x", (v & 0377));
 
188
}
 
189
 
 
190
static void sprint_byte_with_x(char* s, unsigned int v)
 
191
{
 
192
  sprintf(s, "\\x%02x", (v & 0377));
 
193
}
185
194
 
186
195
static int to_ascii(OnigEncoding enc, UChar *s, UChar *end,
187
196
                    UChar buf[], int buf_size, int *is_over)
196
205
    while (p < end) {
197
206
      code = ONIGENC_MBC_TO_CODE(enc, p, end);
198
207
      if (code >= 0x80) {
199
 
        if (len + 5 <= buf_size) {
200
 
          sprintf((char* )(&(buf[len])), "\\x%02X",
201
 
                  (unsigned int )(code & 0377));
202
 
          len += 5;
 
208
        if (code > 0xffff && len + 10 <= buf_size) {
 
209
          sprint_byte_with_x((char*)(&(buf[len])), (unsigned int)(code >> 24));
 
210
          sprint_byte((char*)(&(buf[len+4])),      (unsigned int)(code >> 16));
 
211
          sprint_byte((char*)(&(buf[len+6])),      (unsigned int)(code >>  8));
 
212
          sprint_byte((char*)(&(buf[len+8])),      (unsigned int)code);
 
213
          len += 10;
 
214
        }
 
215
        else if (len + 6 <= buf_size) {
 
216
          sprint_byte_with_x((char*)(&(buf[len])), (unsigned int)(code >> 8));
 
217
          sprint_byte((char*)(&(buf[len+4])),      (unsigned int)code);
 
218
          len += 6;
203
219
        }
204
220
        else {
205
221
          break;
209
225
        buf[len++] = (UChar )code;
210
226
      }
211
227
 
212
 
      p += enc_len(enc, p, end);
 
228
      p += enclen(enc, p, end);
213
229
      if (len >= buf_size) break;
214
230
    }
215
231
 
330
346
    while (p < pat_end) {
331
347
      if (*p == '\\') {
332
348
        *s++ = *p++;
333
 
        len = enc_len(enc, p, pat_end);
 
349
        len = enclen(enc, p, pat_end);
334
350
        while (len-- > 0) *s++ = *p++;
335
351
      }
336
352
      else if (*p == '/') {
338
354
        *s++ = *p++;
339
355
      }
340
356
      else if (ONIGENC_IS_MBC_HEAD(enc, p, pat_end)) {
341
 
        len = enc_len(enc, p, pat_end);
 
357
        len = enclen(enc, p, pat_end);
342
358
        if (ONIGENC_MBC_MINLEN(enc) == 1) {
343
359
          while (len-- > 0) *s++ = *p++;
344
360
        }
346
362
          int blen;
347
363
 
348
364
          while (len-- > 0) {
349
 
            sprintf((char* )bs, "\\x%02X", *p++ & 0377);
 
365
            sprint_byte_with_x((char* )bs, (unsigned int )(*p++));
350
366
            blen = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs);
351
367
            bp = bs;
352
368
            while (blen-- > 0) *s++ = *bp++;
355
371
      }
356
372
      else if (!ONIGENC_IS_CODE_PRINT(enc, *p) &&
357
373
               !ONIGENC_IS_CODE_SPACE(enc, *p)) {
358
 
        sprintf((char* )bs, "\\x%02X", *p++ & 0377);
 
374
        sprint_byte_with_x((char* )bs, (unsigned int )(*p++));
359
375
        len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs);
360
376
        bp = bs;
361
377
        while (len-- > 0) *s++ = *bp++;