2007-08-25 00:14:26 -04:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
encoding.h -
|
|
|
|
|
|
|
|
$Author: matz $
|
|
|
|
$Date: 2007-05-24 11:49:41 +0900 (Thu, 24 May 2007) $
|
|
|
|
created at: Thu May 24 11:49:41 JST 2007
|
|
|
|
|
|
|
|
Copyright (C) 2007 Yukihiro Matsumoto
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef RUBY_ENCODING_H
|
|
|
|
#define RUBY_ENCODING_H 1
|
|
|
|
|
|
|
|
#include "ruby/oniguruma.h"
|
|
|
|
|
2007-12-21 06:00:04 -05:00
|
|
|
#define ENCODING_INLINE_MAX 1023
|
|
|
|
#define ENCODING_SHIFT (FL_USHIFT+10)
|
|
|
|
#define ENCODING_MASK (ENCODING_INLINE_MAX<<ENCODING_SHIFT)
|
2007-08-25 00:14:26 -04:00
|
|
|
#define ENCODING_SET(obj,i) do {\
|
|
|
|
RBASIC(obj)->flags &= ~ENCODING_MASK;\
|
|
|
|
RBASIC(obj)->flags |= i << ENCODING_SHIFT;\
|
|
|
|
} while (0)
|
|
|
|
#define ENCODING_GET(obj) ((RBASIC(obj)->flags & ENCODING_MASK)>>ENCODING_SHIFT)
|
|
|
|
|
2007-12-21 06:00:04 -05:00
|
|
|
#define ENC_CODERANGE_MASK (FL_USER8|FL_USER9)
|
2007-09-26 15:46:58 -04:00
|
|
|
#define ENC_CODERANGE_UNKNOWN 0
|
2007-12-21 06:00:04 -05:00
|
|
|
#define ENC_CODERANGE_7BIT FL_USER8
|
|
|
|
#define ENC_CODERANGE_VALID FL_USER9
|
|
|
|
#define ENC_CODERANGE_BROKEN (FL_USER8|FL_USER9)
|
2007-09-26 15:46:58 -04:00
|
|
|
#define ENC_CODERANGE(obj) (RBASIC(obj)->flags & ENC_CODERANGE_MASK)
|
2007-11-26 21:21:17 -05:00
|
|
|
#define ENC_CODERANGE_ASCIIONLY(obj) (ENC_CODERANGE(obj) == ENC_CODERANGE_7BIT)
|
2007-09-30 04:13:28 -04:00
|
|
|
#define ENC_CODERANGE_SET(obj,cr) (RBASIC(obj)->flags = \
|
|
|
|
(RBASIC(obj)->flags & ~ENC_CODERANGE_MASK) | (cr))
|
2007-09-26 15:46:58 -04:00
|
|
|
#define ENC_CODERANGE_CLEAR(obj) ENC_CODERANGE_SET(obj,0)
|
|
|
|
|
|
|
|
|
2007-08-25 00:14:26 -04:00
|
|
|
typedef OnigEncodingType rb_encoding;
|
|
|
|
|
2007-12-10 07:47:55 -05:00
|
|
|
int rb_enc_replicate(const char *, rb_encoding *);
|
2007-12-21 06:00:04 -05:00
|
|
|
int rb_define_dummy_encoding(const char *);
|
|
|
|
int rb_enc_dummy_p(rb_encoding *);
|
2007-08-25 00:14:26 -04:00
|
|
|
int rb_enc_to_index(rb_encoding*);
|
2007-09-26 05:39:08 -04:00
|
|
|
int rb_enc_get_index(VALUE obj);
|
2007-09-28 15:27:10 -04:00
|
|
|
int rb_enc_find_index(const char *name);
|
2007-10-13 12:32:40 -04:00
|
|
|
int rb_to_encoding_index(VALUE);
|
|
|
|
rb_encoding* rb_to_encoding(VALUE);
|
2007-08-25 00:14:26 -04:00
|
|
|
rb_encoding* rb_enc_get(VALUE);
|
2007-10-21 21:57:08 -04:00
|
|
|
rb_encoding* rb_enc_compatible(VALUE,VALUE);
|
2007-08-25 00:14:26 -04:00
|
|
|
rb_encoding* rb_enc_check(VALUE,VALUE);
|
2007-09-28 15:27:10 -04:00
|
|
|
void rb_enc_associate_index(VALUE, int);
|
2007-08-25 00:14:26 -04:00
|
|
|
void rb_enc_associate(VALUE, rb_encoding*);
|
|
|
|
void rb_enc_copy(VALUE, VALUE);
|
|
|
|
|
2007-08-25 04:05:08 -04:00
|
|
|
VALUE rb_enc_str_new(const char*, long len, rb_encoding*);
|
2007-08-25 00:14:26 -04:00
|
|
|
long rb_enc_strlen(const char*, const char*, rb_encoding*);
|
|
|
|
char* rb_enc_nth(const char*, const char*, int, rb_encoding*);
|
2007-10-04 02:57:19 -04:00
|
|
|
VALUE rb_obj_encoding(VALUE);
|
2007-08-25 00:14:26 -04:00
|
|
|
|
|
|
|
/* index -> rb_encoding */
|
|
|
|
rb_encoding* rb_enc_from_index(int idx);
|
|
|
|
|
|
|
|
/* name -> rb_encoding */
|
|
|
|
rb_encoding * rb_enc_find(const char *name);
|
|
|
|
|
|
|
|
/* encoding -> name */
|
|
|
|
#define rb_enc_name(enc) (enc)->name
|
|
|
|
|
|
|
|
/* encoding -> minlen/maxlen */
|
|
|
|
#define rb_enc_mbminlen(enc) (enc)->min_enc_len
|
|
|
|
#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
|
|
|
|
|
2007-12-23 10:19:23 -05:00
|
|
|
/* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */
|
2007-12-23 09:06:00 -05:00
|
|
|
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc);
|
2007-08-27 09:48:09 -04:00
|
|
|
|
2007-12-10 22:08:50 -05:00
|
|
|
/* -> chlen, invalid or needmore */
|
|
|
|
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc);
|
2007-12-06 04:28:26 -05:00
|
|
|
#define MBCLEN_CHARFOUND(ret) ONIGENC_MBCLEN_CHARFOUND(ret)
|
|
|
|
#define MBCLEN_INVALID(ret) ONIGENC_MBCLEN_INVALID(ret)
|
|
|
|
#define MBCLEN_NEEDMORE(ret) ONIGENC_MBCLEN_NEEDMORE(ret)
|
|
|
|
|
2007-12-10 22:08:50 -05:00
|
|
|
/* -> 0x00..0x7f, -1 */
|
2007-12-11 02:39:16 -05:00
|
|
|
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc);
|
2007-12-07 21:50:43 -05:00
|
|
|
|
2007-12-23 10:19:23 -05:00
|
|
|
/* -> code or raise exception */
|
|
|
|
int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc);
|
2007-12-25 05:01:06 -05:00
|
|
|
#define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE(enc,(UChar*)(p),(UChar*)(e))
|
2007-12-23 10:19:23 -05:00
|
|
|
|
2007-12-27 01:27:39 -05:00
|
|
|
/* -> codelen>0 or raise exception */
|
2007-12-23 09:06:00 -05:00
|
|
|
int rb_enc_codelen(int code, rb_encoding *enc);
|
2007-08-25 00:14:26 -04:00
|
|
|
|
|
|
|
/* code,ptr,encoding -> write buf */
|
2007-12-25 05:01:06 -05:00
|
|
|
#define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC(enc,c,(UChar*)(buf))
|
2007-08-25 00:14:26 -04:00
|
|
|
|
|
|
|
/* ptr, ptr, encoding -> prev_char */
|
2007-12-25 05:01:06 -05:00
|
|
|
#define rb_enc_prev_char(s,p,enc) (char *)onigenc_get_prev_char_head(enc,(UChar*)(s),(UChar*)(p))
|
2007-12-24 11:36:14 -05:00
|
|
|
/* ptr, ptr, encoding -> next_char */
|
2007-12-25 05:01:06 -05:00
|
|
|
#define rb_enc_left_char_head(s,p,enc) (char *)onigenc_get_left_adjust_char_head(enc,(UChar*)(s),(UChar*)(p))
|
|
|
|
#define rb_enc_right_char_head(s,p,enc) (char *)onigenc_get_right_adjust_char_head(enc,(UChar*)(s),(UChar*)(p))
|
2007-08-25 00:14:26 -04:00
|
|
|
|
2007-09-28 15:27:10 -04:00
|
|
|
#define rb_enc_isctype(c,t,enc) ONIGENC_IS_CODE_CTYPE(enc,c,t)
|
2007-08-25 00:14:26 -04:00
|
|
|
#define rb_enc_isascii(c,enc) ONIGENC_IS_CODE_ASCII(c)
|
|
|
|
#define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA(enc,c)
|
|
|
|
#define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER(enc,c)
|
|
|
|
#define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER(enc,c)
|
|
|
|
#define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM(enc,c)
|
|
|
|
#define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT(enc,c)
|
|
|
|
#define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE(enc,c)
|
|
|
|
#define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT(enc,c)
|
|
|
|
|
2007-09-26 05:39:08 -04:00
|
|
|
#define rb_enc_asciicompat(enc) (rb_enc_mbminlen(enc)==1)
|
|
|
|
|
2007-12-25 05:01:06 -05:00
|
|
|
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc);
|
2007-08-25 00:14:26 -04:00
|
|
|
int rb_enc_toupper(int c, rb_encoding *enc);
|
|
|
|
int rb_enc_tolower(int c, rb_encoding *enc);
|
|
|
|
ID rb_intern3(const char*, long, rb_encoding*);
|
2007-12-25 05:01:06 -05:00
|
|
|
ID rb_interned_id_p(const char *, long, rb_encoding *);
|
2007-09-26 05:39:08 -04:00
|
|
|
int rb_enc_symname_p(const char*, rb_encoding*);
|
2007-09-26 15:46:58 -04:00
|
|
|
int rb_enc_str_coderange(VALUE);
|
2007-11-25 08:25:34 -05:00
|
|
|
int rb_enc_str_asciionly_p(VALUE);
|
|
|
|
#define rb_enc_str_asciicompat_p(str) rb_enc_asciicompat(rb_enc_get(str))
|
2007-10-16 16:07:20 -04:00
|
|
|
VALUE rb_enc_from_encoding(rb_encoding *enc);
|
2007-12-22 18:47:18 -05:00
|
|
|
rb_encoding *rb_ascii8bit_encoding(void);
|
2007-12-21 01:59:48 -05:00
|
|
|
rb_encoding *rb_utf8_encoding(void);
|
2007-12-01 09:05:53 -05:00
|
|
|
rb_encoding *rb_default_external_encoding(void);
|
|
|
|
VALUE rb_enc_default_external(void);
|
|
|
|
void rb_enc_set_default_external(VALUE encoding);
|
2007-12-20 21:52:23 -05:00
|
|
|
VALUE rb_locale_charmap(VALUE klass);
|
2007-08-25 00:14:26 -04:00
|
|
|
|
|
|
|
#endif /* RUBY_ENCODING_H */
|