move sauerlib encoding into its own header
This commit is contained in:
parent
5b7e1e6dd2
commit
9bc4942489
11 changed files with 64 additions and 42 deletions
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "command.hh"
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include <shared/igame.hh>
|
||||
|
||||
#include "console.hh"
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "console.hh"
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/glemu.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <new>
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/glemu.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "shader.hh"
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/glemu.hh>
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <ctime>
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <new>
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
||||
|
|
46
src/sauerlib/encoding.hh
Normal file
46
src/sauerlib/encoding.hh
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef SAUERLIB_ENCODING_HH
|
||||
#define SAUERLIB_ENCODING_HH
|
||||
|
||||
enum
|
||||
{
|
||||
CT_PRINT = 1<<0,
|
||||
CT_SPACE = 1<<1,
|
||||
CT_DIGIT = 1<<2,
|
||||
CT_ALPHA = 1<<3,
|
||||
CT_LOWER = 1<<4,
|
||||
CT_UPPER = 1<<5,
|
||||
CT_UNICODE = 1<<6
|
||||
};
|
||||
extern const unsigned char cubectype[256];
|
||||
static inline int iscubeprint(unsigned char c) { return cubectype[c]&CT_PRINT; }
|
||||
static inline int iscubespace(unsigned char c) { return cubectype[c]&CT_SPACE; }
|
||||
static inline int iscubealpha(unsigned char c) { return cubectype[c]&CT_ALPHA; }
|
||||
static inline int iscubealnum(unsigned char c) { return cubectype[c]&(CT_ALPHA|CT_DIGIT); }
|
||||
static inline int iscubelower(unsigned char c) { return cubectype[c]&CT_LOWER; }
|
||||
static inline int iscubeupper(unsigned char c) { return cubectype[c]&CT_UPPER; }
|
||||
static inline int iscubepunct(unsigned char c) { return cubectype[c] == CT_PRINT; }
|
||||
static inline int cube2uni(unsigned char c)
|
||||
{
|
||||
extern const int cube2unichars[256];
|
||||
return cube2unichars[c];
|
||||
}
|
||||
static inline unsigned char uni2cube(int c)
|
||||
{
|
||||
extern const int uni2cubeoffsets[8];
|
||||
extern const unsigned char uni2cubechars[];
|
||||
return static_cast<unsigned int>(c) <= 0x7FF ? uni2cubechars[uni2cubeoffsets[c>>8] + (c&0xFF)] : 0;
|
||||
}
|
||||
static inline unsigned char cubelower(unsigned char c)
|
||||
{
|
||||
extern const unsigned char cubelowerchars[256];
|
||||
return cubelowerchars[c];
|
||||
}
|
||||
static inline unsigned char cubeupper(unsigned char c)
|
||||
{
|
||||
extern const unsigned char cubeupperchars[256];
|
||||
return cubeupperchars[c];
|
||||
}
|
||||
extern size_t decodeutf8(unsigned char *dst, size_t dstlen, const unsigned char *src, size_t srclen, size_t *carry = nullptr);
|
||||
extern size_t encodeutf8(unsigned char *dstbuf, size_t dstlen, const unsigned char *srcbuf, size_t srclen, size_t *carry = nullptr);
|
||||
|
||||
#endif
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "tools.hh"
|
||||
|
||||
#include "encoding.hh"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
////////////////////////// strings ////////////////////////////////////////
|
||||
|
|
|
@ -1231,48 +1231,6 @@ struct streambuf
|
|||
size_t length() { return s->size(); }
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CT_PRINT = 1<<0,
|
||||
CT_SPACE = 1<<1,
|
||||
CT_DIGIT = 1<<2,
|
||||
CT_ALPHA = 1<<3,
|
||||
CT_LOWER = 1<<4,
|
||||
CT_UPPER = 1<<5,
|
||||
CT_UNICODE = 1<<6
|
||||
};
|
||||
extern const uchar cubectype[256];
|
||||
static inline int iscubeprint(uchar c) { return cubectype[c]&CT_PRINT; }
|
||||
static inline int iscubespace(uchar c) { return cubectype[c]&CT_SPACE; }
|
||||
static inline int iscubealpha(uchar c) { return cubectype[c]&CT_ALPHA; }
|
||||
static inline int iscubealnum(uchar c) { return cubectype[c]&(CT_ALPHA|CT_DIGIT); }
|
||||
static inline int iscubelower(uchar c) { return cubectype[c]&CT_LOWER; }
|
||||
static inline int iscubeupper(uchar c) { return cubectype[c]&CT_UPPER; }
|
||||
static inline int iscubepunct(uchar c) { return cubectype[c] == CT_PRINT; }
|
||||
static inline int cube2uni(uchar c)
|
||||
{
|
||||
extern const int cube2unichars[256];
|
||||
return cube2unichars[c];
|
||||
}
|
||||
static inline uchar uni2cube(int c)
|
||||
{
|
||||
extern const int uni2cubeoffsets[8];
|
||||
extern const uchar uni2cubechars[];
|
||||
return uint(c) <= 0x7FF ? uni2cubechars[uni2cubeoffsets[c>>8] + (c&0xFF)] : 0;
|
||||
}
|
||||
static inline uchar cubelower(uchar c)
|
||||
{
|
||||
extern const uchar cubelowerchars[256];
|
||||
return cubelowerchars[c];
|
||||
}
|
||||
static inline uchar cubeupper(uchar c)
|
||||
{
|
||||
extern const uchar cubeupperchars[256];
|
||||
return cubeupperchars[c];
|
||||
}
|
||||
extern size_t decodeutf8(uchar *dst, size_t dstlen, const uchar *src, size_t srclen, size_t *carry = nullptr);
|
||||
extern size_t encodeutf8(uchar *dstbuf, size_t dstlen, const uchar *srcbuf, size_t srclen, size_t *carry = nullptr);
|
||||
|
||||
extern string homedir;
|
||||
|
||||
extern char *makerelpath(const char *dir, const char *file, const char *prefix = nullptr, const char *cmd = nullptr);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <new>
|
||||
|
||||
#include <sauerlib/encoding.hh>
|
||||
|
||||
#include "command.hh"
|
||||
|
||||
#include <engine/console.hh> /* conoutf */
|
||||
|
|
Loading…
Reference in a new issue