OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [gcj/] [convert/] [natOutput_EUCJIS.cc] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
/* Copyright (C) 1999  Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
This software is copyrighted work licensed under the terms of the
6
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
details.  */
8
 
9
#include <config.h>
10
#include <gcj/cni.h>
11
#include <gnu/gcj/convert/Output_EUCJIS.h>
12
 
13
/* A trie structure to map unicode values to JIS codes.
14
 * code == -1: the character is undefined.
15
 * code >= 0 && code < 128:  JIS-Roman - mostly Ascii.
16
 * code >= 128 && code < 256:  Half-width Katakana.
17
 * code >= 256 && code < 0x8000:  JIS X 0208:1997.
18
 * code >= 0x8000 && code < 0xFFFF:  JIX X 0212-1990.
19
 */
20
 
21
extern unsigned short Unicode_to_JIS[];
22
 
23
int
24
trie_lookup (unsigned short *trie, unsigned short key)
25
{
26
  unsigned short branch = trie[(key >> 12) & 0xf];
27
  if (branch == 0)
28
    return -1;
29
  branch = trie[branch + ((key >> 8) & 0xf)];
30
  if (branch == 0)
31
    return -1;
32
  branch = trie[branch + ((key >> 4) & 0xf)];
33
  if (branch == 0)
34
    return -1;
35
  return trie[branch + (key & 0xf)];
36
}
37
 
38
static jint
39
convert_TO_EUCJIS (gnu::gcj::convert::Output_EUCJIS *encoder,
40
                          jchar *ptr, jint inlength)
41
{
42
  int orig_inlength = inlength;
43
  jint outbuf_length = encoder->buf->length;
44
  for (;;)
45
    {
46
      if (encoder->count >= outbuf_length)
47
        break;
48
      if (encoder->pending1 >= 0)
49
        {
50
          elements(encoder->buf)[encoder->count++] = encoder->pending1;
51
          encoder->pending1 = encoder->pending2;
52
          encoder->pending2 = -1;
53
          continue;
54
        }
55
      if (inlength == 0)
56
        break;
57
      jchar ch = *ptr++;
58
      inlength--;
59
      unsigned short val = trie_lookup(Unicode_to_JIS, ch);
60
      if (val < 0x80)
61
        {
62
          if (val == 0xffff)
63
            val = '?';
64
        }
65
      else if (val <= 0xFF)
66
        {
67
          encoder->pending1 = val;
68
          encoder->pending2 = -1;
69
          val = 0x8e;
70
        }
71
      else if (val < 0x8000)
72
        {
73
          val |= 0x8080;
74
          encoder->pending1 = val & 0xff;
75
          val = val >> 8;
76
          encoder->pending2 = -1;
77
        }
78
      else
79
        {
80
          val |= 0x8080;
81
          encoder->pending1 = val >> 8;
82
          encoder->pending2 = val & 0xff;
83
          val = 0x8f;
84
        }
85
      elements(encoder->buf)[encoder->count++] = val;
86
    }
87
  return orig_inlength - inlength;
88
}
89
 
90
jint
91
gnu::gcj::convert::Output_EUCJIS::write (jcharArray inbuffer,
92
                                         jint inpos, jint inlength)
93
{
94
  return convert_TO_EUCJIS(this, &elements(inbuffer)[inpos], inlength);
95
}
96
 
97
jint
98
gnu::gcj::convert::Output_EUCJIS::write (jstring str, jint inpos,
99
                                         jint inlength, jcharArray)
100
{
101
  return convert_TO_EUCJIS(this, _Jv_GetStringChars(str)+inpos, inlength);
102
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.