awtk/tools/str_gen/str_gen.h

79 lines
1.6 KiB
C
Raw Normal View History

2018-05-04 11:47:09 +08:00
/**
* File: str_gen.h
2018-05-15 09:31:58 +08:00
* Author: AWTK Develop Team
2018-05-04 11:47:09 +08:00
* Brief: str_gen
*
2020-01-01 11:27:36 +08:00
* Copyright (c) 2018 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
2018-05-04 11:47:09 +08:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-05-03 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_STR_GEN_H
#define TK_STR_GEN_H
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include "tkc/types_def.h"
2018-05-04 11:47:09 +08:00
using std::map;
using std::pair;
using std::string;
using std::vector;
class Sentence {
public:
Sentence(const string& key, const string& value) {
this->key = key;
this->value = value;
}
2018-06-03 10:19:34 +08:00
bool operator<(const Sentence& other) const {
return this->key < other.key;
}
2018-05-04 11:47:09 +08:00
string key;
string value;
};
class Sentences {
public:
2018-06-03 10:19:34 +08:00
void Add(const Sentence& s) {
this->sentences.push_back(s);
}
2018-05-04 11:47:09 +08:00
2018-06-03 10:19:34 +08:00
void Sort() {
std::sort(this->sentences.begin(), this->sentences.end());
}
2018-05-04 11:47:09 +08:00
vector<Sentence> sentences;
};
typedef map<string, Sentences> StrTable;
class StrGen {
public:
void Add(const string& language, const Sentence& sentence);
uint8_t* Output(const string& language, uint8_t* buff, uint32_t max_size);
vector<string> GetLanguages();
private:
uint8_t* OutputSentences(const Sentences& sentences, uint8_t* buff, uint32_t max_size);
StrTable str_table;
};
#endif /*TK_STR_GEN_H*/