Switch to unified view

a/src/unac/unac.c b/src/unac/unac.c
...
...
28
#include <vector>
28
#include <vector>
29
#include <map>
29
#include <map>
30
#include <string>
30
#include <string>
31
#include <algorithm>
31
#include <algorithm>
32
#include <iostream>
32
#include <iostream>
33
#include UNORDERED_MAP_INCLUDE
33
#include <unordered_map>
34
34
#include <mutex>
35
36
#include "smallut.h"
37
35
38
using std::string;
36
using std::string;
39
using std::vector;
37
using std::vector;
38
39
#include "smallut.h"
40
40
41
/* 
41
/* 
42
   Storage for the exception translations. These are chars which
42
   Storage for the exception translations. These are chars which
43
   should not be translated according to what UnicodeData says, but
43
   should not be translated according to what UnicodeData says, but
44
   instead according to some local rule. There will usually be very
44
   instead according to some local rule. There will usually be very
45
   few of them, but they must be looked up for every translated char.
45
   few of them, but they must be looked up for every translated char.
46
 */
46
 */
47
STD_UNORDERED_MAP<unsigned short, string> except_trans;
47
std::unordered_map<unsigned short, string> except_trans;
48
static inline bool is_except_char(unsigned short c, string& trans)
48
static inline bool is_except_char(unsigned short c, string& trans)
49
{
49
{
50
    STD_UNORDERED_MAP<unsigned short, string>::const_iterator it 
51
  = except_trans.find(c);
50
    auto it = except_trans.find(c);
52
    if (it == except_trans.end())
51
    if (it == except_trans.end())
53
    return false;
52
    return false;
54
    trans = it->second;
53
    trans = it->second;
55
    return true;
54
    return true;
56
}
55
}
...
...
74
#include <errno.h>
73
#include <errno.h>
75
#ifdef HAVE_VSNPRINTF
74
#ifdef HAVE_VSNPRINTF
76
#include <stdio.h>
75
#include <stdio.h>
77
#include <stdarg.h>
76
#include <stdarg.h>
78
#endif /* HAVE_VSNPRINTF */
77
#endif /* HAVE_VSNPRINTF */
79
#include <pthread.h>
80
78
81
#include "unac.h"
79
#include "unac.h"
82
#include "unac_version.h"
80
#include "unac_version.h"
83
81
84
/* Generated by builder. Do not modify. Start tables */
82
/* Generated by builder. Do not modify. Start tables */
...
...
14312
}
14310
}
14313
14311
14314
static const char *utf16be = "UTF-16BE";
14312
static const char *utf16be = "UTF-16BE";
14315
static iconv_t u8tou16_cd = (iconv_t)-1;
14313
static iconv_t u8tou16_cd = (iconv_t)-1;
14316
static iconv_t u16tou8_cd = (iconv_t)-1;
14314
static iconv_t u16tou8_cd = (iconv_t)-1;
14317
static pthread_mutex_t o_unac_mutex;
14315
static std::mutex o_unac_mutex;
14318
static int unac_mutex_is_init;
14319
// Call this or take your chances with the auto init.
14320
void unac_init_mt()
14321
{
14322
    pthread_mutex_init(&o_unac_mutex, 0);
14323
    unac_mutex_is_init = 1;
14324
}
14325
14316
14326
/*
14317
/*
14327
 * Convert buffer <in> containing string encoded in charset <from> into
14318
 * Convert buffer <in> containing string encoded in charset <from> into
14328
 * a string in charset <to> and return it in buffer <outp>. The <outp>
14319
 * a string in charset <to> and return it in buffer <outp>. The <outp>
14329
 * points to a malloced string large enough to hold the conversion result.
14320
 * points to a malloced string large enough to hold the conversion result.
...
...
14341
  size_t out_size;
14332
  size_t out_size;
14342
  char* out_base;
14333
  char* out_base;
14343
  int from_utf16, from_utf8, to_utf16, to_utf8, u8tou16, u16tou8;
14334
  int from_utf16, from_utf8, to_utf16, to_utf8, u8tou16, u16tou8;
14344
  const char space[] = { 0x00, 0x20 };
14335
  const char space[] = { 0x00, 0x20 };
14345
14336
14346
  /* Note: better call explicit unac_init_mt() before starting threads than
14337
  std::unique_lock<std::mutex> lock(o_unac_mutex);
14347
     rely on this.
14348
   */
14349
  if (unac_mutex_is_init == 0) {
14350
      pthread_mutex_init(&o_unac_mutex, 0);
14351
      unac_mutex_is_init = 1;
14352
  }
14353
  pthread_mutex_lock(&o_unac_mutex);
14354
14338
14355
  if (!strcmp(utf16be, from)) {
14339
  if (!strcmp(utf16be, from)) {
14356
      from_utf8 = 0;
14340
      from_utf8 = 0;
14357
      from_utf16 = 1;
14341
      from_utf16 = 1;
14358
  } else if (!strcasecmp("UTF-8", from)) {
14342
  } else if (!strcasecmp("UTF-8", from)) {
...
...
14492
  *out_lengthp = out - out_base;
14476
  *out_lengthp = out - out_base;
14493
  (*outp)[*out_lengthp] = '\0';
14477
  (*outp)[*out_lengthp] = '\0';
14494
14478
14495
  ret = 0;
14479
  ret = 0;
14496
out:
14480
out:
14497
  pthread_mutex_unlock(&o_unac_mutex);
14498
  return ret;
14481
  return ret;
14499
}
14482
}
14500
14483
14501
int unacmaybefold_string(const char* charset,
14484
int unacmaybefold_string(const char* charset,
14502
             const char* in, size_t in_length,
14485
             const char* in, size_t in_length,