• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 *   Copyright (C) 2009-2012, International Business Machines
7 *   Corporation and others.  All Rights Reserved.
8 *
9 *******************************************************************************
10 */
11 
12 #ifndef _ICUGLUE_H
13 #define _ICUGLUE_H
14 
15 /* Get utypes.h from whatever ICU we are under */
16 #include <unicode/utypes.h>
17 
18 #define GLUE_SYM_V(x, v) glue ## x ## v
19 
20 /**
21  * how to parse a version string.
22  * old:  3_6_X, 3_8_X, 4_4_X, 4_8_X
23  * new:  49_X, 50_X, 51_X, ...
24  *
25  * example use:
26  *  char *str = "50_0_0", str1="49_1_2",str2="4_8_1_1";
27  *  if(IS_OLD_VERSION(str)) {
28  *    maj = str[OLD_VERSTR_MAJ];
29  *    min = str[OLD_VERSTR_MIN];
30  *  } else {
31  *    maj = str[NEW_VERSTR_MAJ];
32  *    min = str[NEW_VERSTR_MIN];
33  *  }
34  */
35 #define IS_OLD_VERSTR(x) ((x[0]<'4') || ((x[0]=='4') && (x[2]<'9') && (x[2]>='0')))
36 #define OLD_VERSTR_MAJ 0
37 #define OLD_VERSTR_MIN 2
38 #define NEW_VERSTR_MAJ 0
39 #define NEW_VERSTR_MIN 1
40 
41 /**
42  * copy version into dst[0] and dst[1]
43  * does not modify dst ptr
44  */
45 #define CPY_VERSTR(dst,ver) if(IS_OLD_VERSTR(ver)) \
46     { \
47       (dst)[0]=ver[OLD_VERSTR_MAJ];              \
48       (dst)[1]=ver[OLD_VERSTR_MIN];              \
49     } else {                      \
50       (dst)[0]=ver[NEW_VERSTR_MAJ];       \
51       (dst)[1]=ver[NEW_VERSTR_MIN];             \
52     }
53 
54 /**
55  * compare a verstr to a string
56  * @param str a 2 char string such as "50", "44", "49"
57  * @param ver a verstr such as "50_0_2", "4_8_1_1", etc
58  * @return true or false
59  */
60 
61 #define CMP_VERSTR(str,ver) \
62   ( (IS_OLD_VERSTR(ver)) ? \
63      ( \
64       (str)[0]==ver[OLD_VERSTR_MAJ] &&              \
65       (str)[1]==ver[OLD_VERSTR_MIN] \
66      ):(                                              \
67       (str)[0]==ver[NEW_VERSTR_MAJ]&&       \
68       (str)[1]==ver[NEW_VERSTR_MIN]             \
69      ) \
70    )
71 
72 #endif
73