File: unijp.c

package info (click to toggle)
libunicode-japanese-perl 0.50-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,376 kB
  • sloc: ansic: 30,821; perl: 5,635; erlang: 224; makefile: 191
file content (74 lines) | stat: -rw-r--r-- 2,295 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ----------------------------------------------------------------------------
 * unijp.c
 * ----------------------------------------------------------------------------
 * Mastering programmed by YAMASHINA Hio
 *
 * Copyright 2008 YAMASHINA Hio
 * ----------------------------------------------------------------------------
 * $Id$
 * ------------------------------------------------------------------------- */

#include "unijp.h"
#include "unijp_build.h"
#include <assert.h>

/* ----------------------------------------------------------------------------
: uj_new(str, bytes_len, icode).
: uj_new_r(alloc, str, bytes_len, icode).
+--------------------------------------------------------------------------- */
unijp_t* uj_new(const uj_uint8* str, uj_size_t bytes, uj_charcode_t icode)
{
  return uj_new_r(_uj_default_alloc, str, bytes, icode);
}

unijp_t* uj_new_r(const uj_alloc_t* const alloc, const uj_uint8* str, uj_size_t bytes, uj_charcode_t icode)
{
  unijp_t* uj;
  uj_conv_t conv_in;
  uj_conv_t conv_out;
  uj_conv_t* conv_ret;

  _uj_conv_set_const(&conv_in, alloc, str, bytes);
  conv_ret = _uj_any_to_utf8(&conv_in, &conv_out, icode);
  if( conv_ret != NULL )
  {
    assert( conv_ret == &conv_out );
    uj = _uj_alloc(alloc, sizeof(*uj));
    if( uj!=NULL )
    {
      _uj_conv_own_string(&conv_out);
      uj->alloc     = alloc;
      uj->data      = conv_out.buf;
      uj->data_len  = conv_out.buf_len;
      uj->is_binary = icode==ujc_binary;
    }else
    {
      _uj_conv_free_buffer(&conv_out);
    }
  }else
  {
    uj = NULL;
  }
  return uj;
}

/* ----------------------------------------------------------------------------
: uj_delete(uj).
+--------------------------------------------------------------------------- */
void uj_delete(unijp_t* uj)
{
  _uj_free(uj->alloc, uj->data);
  _uj_free(uj->alloc, uj);
}

/* ----------------------------------------------------------------------------
: uj_delete_buffer(uj, ptr).
+--------------------------------------------------------------------------- */
void uj_delete_buffer(unijp_t* uj, uj_uint8* ptr)
{
  _uj_free(uj->alloc, ptr);
}

/* ----------------------------------------------------------------------------
 * End of File.
 * ------------------------------------------------------------------------- */