2013-08-02 13:12:24 -07:00
|
|
|
// Matt Wells, copyright Jul 2005
|
|
|
|
|
2016-03-08 22:14:30 +01:00
|
|
|
#ifndef GB_POS_H
|
|
|
|
#define GB_POS_H
|
2013-08-02 13:12:24 -07:00
|
|
|
|
2016-01-20 13:32:13 +01:00
|
|
|
#include <stdint.h>
|
2016-04-14 23:05:44 +02:00
|
|
|
#include "TitleRecVersion.h"
|
2016-01-20 13:32:13 +01:00
|
|
|
|
2013-08-02 13:12:24 -07:00
|
|
|
// this class is used to measure the number of characters between two "words"
|
|
|
|
// (as defined in the Words.cpp class) in units of "characters". A utf8
|
|
|
|
// character can be 1, 2, 3 or 4 bytes, so be careful.
|
|
|
|
|
|
|
|
#define POS_LOCALBUFSIZE 20
|
|
|
|
|
2016-01-12 15:33:42 +01:00
|
|
|
class Words;
|
|
|
|
|
2013-08-02 13:12:24 -07:00
|
|
|
class Pos {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Pos();
|
|
|
|
~Pos();
|
|
|
|
void reset();
|
|
|
|
|
2016-05-23 16:55:18 +02:00
|
|
|
bool set(const Words *words, int32_t a = 0, int32_t b = -1 );
|
2013-08-02 13:12:24 -07:00
|
|
|
|
2016-01-20 13:32:13 +01:00
|
|
|
// . filter out xml words [a,b] into plain text, stores into "f"
|
|
|
|
// . will not exceed "fend"
|
|
|
|
// . returns number of BYTES stored into "f"
|
2016-05-24 16:55:50 +02:00
|
|
|
int32_t filter( const Words *words, int32_t a, int32_t b, bool addEllipsis, char *f, char *fend,
|
2016-01-29 19:18:22 +01:00
|
|
|
int32_t version = TITLEREC_CURRENT_VERSION );
|
2013-08-02 13:12:24 -07:00
|
|
|
|
|
|
|
// . the position in CHARACTERS of word i is given by m_pos[i]
|
|
|
|
// . this is NOT the byte position. you can have 2, 3 or even 4
|
|
|
|
// byte characters in utf8. the purpose here is for counting
|
|
|
|
// "letters" or "characters" for formatting purposes.
|
2014-11-10 14:45:11 -08:00
|
|
|
int32_t *m_pos;
|
2013-08-02 13:12:24 -07:00
|
|
|
|
2016-01-20 13:32:13 +01:00
|
|
|
private:
|
2013-08-02 13:12:24 -07:00
|
|
|
char m_localBuf [ POS_LOCALBUFSIZE ];
|
|
|
|
char *m_buf;
|
2014-11-10 14:45:11 -08:00
|
|
|
int32_t m_bufSize;
|
2013-08-02 13:12:24 -07:00
|
|
|
|
|
|
|
bool m_needsFree;
|
|
|
|
};
|
|
|
|
|
2016-03-08 22:14:30 +01:00
|
|
|
#endif // GB_POS_H
|