summaryrefslogtreecommitdiff
path: root/ACE/ace/Codeset_Registry.cpp
blob: b98a1dd7e891a1fab76b2199799d984768420a54 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//=============================================================================
/**
 *  @file   Codeset_Registry.cpp
 *
 *  $Id$
 *
 *  emulated codset regstry functions
 *
 *
 *  @author Phil Mesnier <mesnier_p@ociweb.com>
 */
//=============================================================================

#include "ace/Codeset_Registry.h"
#include "ace/OS_Memory.h"
#include "ace/OS_NS_string.h"

// $Id$

#if !defined (__ACE_INLINE__)
#include "ace/Codeset_Registry.inl"
#endif /* __ACE_INLINE__ */

ACE_RCSID (ace,
           Codeset_Registry,
           "$Id$")

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

int
ACE_Codeset_Registry::locale_to_registry_i (const ACE_CString &locale,
                                            ACE_CDR::ULong &codeset_id,
                                            ACE_CDR::UShort *num_sets,
                                            ACE_CDR::UShort **char_sets)
{
  registry_entry const *element = 0;
  for (size_t i = 0; element == 0 && i < num_registry_entries_; i++)
    if (ACE_OS::strcmp (registry_db_[i].loc_name_, locale.c_str ()) == 0)
      element = &registry_db_[i];
  if (element == 0)
    return 0;
  codeset_id = element->codeset_id_;
  if (num_sets != 0)
    *num_sets = element->num_sets_;
  if (char_sets != 0)
    {
      ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0);
      ACE_OS::memcpy (*char_sets, element->char_sets_,
                      element->num_sets_ * sizeof (ACE_CDR::UShort));
    }
  return 1;
}

int
ACE_Codeset_Registry::registry_to_locale_i (ACE_CDR::ULong codeset_id,
                                            ACE_CString &locale,
                                            ACE_CDR::UShort *num_sets,
                                            ACE_CDR::UShort **char_sets)
{
  registry_entry const *element = 0;
  for (size_t i = 0; element == 0 && i < num_registry_entries_; i++)
    if (codeset_id == registry_db_[i].codeset_id_)
      element = &registry_db_[i];
  if (element == 0)
    return 0;
  locale.set (element->loc_name_);
  if (num_sets != 0)
    *num_sets = element->num_sets_;
  if (char_sets != 0)
    {
      ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0);
      ACE_OS::memcpy (*char_sets, element->char_sets_,
                      element->num_sets_ * sizeof (ACE_CDR::UShort));
    }
  return 1;
}

int
ACE_Codeset_Registry::is_compatible_i (ACE_CDR::ULong codeset_id,
                                       ACE_CDR::ULong other)
{
  registry_entry const *lhs = 0;
  registry_entry const *rhs = 0;
  for (size_t i = 0; (lhs == 0 || rhs == 0) && i < num_registry_entries_; i++)
    {
      if (codeset_id == registry_db_[i].codeset_id_)
        lhs = &registry_db_[i];
      if (other == registry_db_[i].codeset_id_)
        rhs = &registry_db_[i];
    }

  if (lhs == 0 || rhs == 0)
    return 0;

  for (ACE_CDR::UShort l = 0; l < lhs->num_sets_; l++)
    for (ACE_CDR::UShort r = 0; r < rhs->num_sets_; r++)
      if (rhs->char_sets_[r] == lhs->char_sets_[l])
        return 1;
  return 0;
}

ACE_CDR::Short
ACE_Codeset_Registry::get_max_bytes_i (ACE_CDR::ULong codeset_id)
{
  for (size_t i = 0; i < num_registry_entries_; i++)
    if (codeset_id == registry_db_[i].codeset_id_)
      return registry_db_[i].max_bytes_;
  return 0;
}

ACE_END_VERSIONED_NAMESPACE_DECL