File: common.h

package info (click to toggle)
ruby-charlock-holmes 0.7.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116 kB
  • sloc: ansic: 325; ruby: 153; cpp: 101; sh: 21; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef CHARLOCK_COMMON_H
#define CHARLOCK_COMMON_H

// tell rbx not to use it's caching compat layer
// by doing this we're making a promize to RBX that
// we'll never modify the pointers we get back from RSTRING_PTR
#define RSTRING_NOT_MODIFIED

#include <ruby.h>
#ifdef HAVE_RUBY_ENCODING_H
#include <ruby/encoding.h>
#endif

static inline VALUE charlock_new_enc_str(const char *str, size_t len, void *encoding)
{
#ifdef HAVE_RUBY_ENCODING_H
	return rb_external_str_new_with_enc(str, len, (rb_encoding *)encoding);
#else
	return rb_str_new(str, len);
#endif
}

static inline VALUE charlock_new_str(const char *str, size_t len)
{
#ifdef HAVE_RUBY_ENCODING_H
	return rb_external_str_new_with_enc(str, len, rb_utf8_encoding());
#else
	return rb_str_new(str, len);
#endif
}

static inline VALUE charlock_new_str2(const char *str)
{
#ifdef HAVE_RUBY_ENCODING_H
	return rb_external_str_new_with_enc(str, strlen(str), rb_utf8_encoding());
#else
	return rb_str_new2(str);
#endif
}


#ifdef __cplusplus
extern "C"
{
#endif

extern void Init_charlock_holmes(void);
extern void _init_charlock_encoding_detector(void);
extern void _init_charlock_converter(void);
extern void _init_charlock_transliterator(void);

#ifdef __cplusplus
}
#endif

#endif