2015-04-12 01:22:19 +00:00
|
|
|
/*
|
2015-05-01 00:14:23 +00:00
|
|
|
* ace_break_line.cpp
|
2015-04-12 01:22:19 +00:00
|
|
|
*
|
|
|
|
* Takes a string and insert as many line breaks as needed so it fits a given width
|
|
|
|
*
|
|
|
|
* Takes:
|
|
|
|
* Localized string as string
|
|
|
|
* Example: "Check weapon temperature"
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* String with line breaks
|
|
|
|
*/
|
|
|
|
|
2015-05-13 15:34:14 +00:00
|
|
|
#include "shared.hpp"
|
2015-04-12 01:22:19 +00:00
|
|
|
|
2016-02-17 21:31:12 +00:00
|
|
|
#include <stdlib.h>
|
2015-04-12 01:22:19 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2015-04-12 02:39:06 +00:00
|
|
|
#define MAXCHARACTERS 14
|
2015-04-12 01:22:19 +00:00
|
|
|
|
|
|
|
extern "C" {
|
2015-05-17 17:10:02 +00:00
|
|
|
EXPORT void __stdcall RVExtension(char *output, int outputSize, const char *function);
|
2015-09-08 19:53:29 +00:00
|
|
|
}
|
2015-04-12 01:22:19 +00:00
|
|
|
|
2015-04-14 21:24:50 +00:00
|
|
|
std::vector<std::string> splitString(const std::string & input) {
|
2015-04-12 01:22:19 +00:00
|
|
|
std::istringstream ss(input);
|
|
|
|
std::string token;
|
|
|
|
|
|
|
|
std::vector<std::string> output;
|
2015-04-12 02:39:06 +00:00
|
|
|
while (std::getline(ss, token, ' ')) {
|
2015-04-12 01:22:19 +00:00
|
|
|
output.push_back(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-04-12 02:39:06 +00:00
|
|
|
std::string addLineBreaks(const std::vector<std::string> &words) {
|
2015-04-12 01:22:19 +00:00
|
|
|
std::stringstream sstream;
|
2015-04-21 23:50:01 +00:00
|
|
|
size_t numChar = 0;
|
|
|
|
size_t i = 0;
|
2015-04-14 21:24:50 +00:00
|
|
|
|
2015-04-12 02:39:06 +00:00
|
|
|
while (i < words.size()) {
|
|
|
|
if (numChar == 0) {
|
|
|
|
sstream << words[i];
|
|
|
|
numChar += words[i].size();
|
|
|
|
i++;
|
2015-04-12 01:22:19 +00:00
|
|
|
} else {
|
2015-04-12 02:39:06 +00:00
|
|
|
if (numChar + 1 + words[i].size() > MAXCHARACTERS) {
|
|
|
|
sstream << "<br/>";
|
|
|
|
numChar = 0;
|
|
|
|
} else {
|
|
|
|
sstream << " " << words[i];
|
|
|
|
numChar += 1 + words[i].size();
|
|
|
|
i++;
|
|
|
|
}
|
2015-04-12 01:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-17 21:31:12 +00:00
|
|
|
|
2015-04-12 01:22:19 +00:00
|
|
|
return sstream.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
|
2015-05-13 15:34:14 +00:00
|
|
|
ZERO_OUTPUT();
|
2015-04-12 01:22:19 +00:00
|
|
|
if (!strcmp(function, "version")) {
|
2016-02-17 21:31:12 +00:00
|
|
|
strncpy_s(output, outputSize, ACE_FULL_VERSION_STR, _TRUNCATE);
|
2015-04-12 01:22:19 +00:00
|
|
|
} else {
|
2016-02-17 21:31:12 +00:00
|
|
|
strncpy_s(output, outputSize, addLineBreaks(splitString(function)).c_str(), _TRUNCATE);
|
2015-04-12 01:22:19 +00:00
|
|
|
}
|
2015-05-13 15:34:14 +00:00
|
|
|
EXTENSION_RETURN();
|
2015-04-12 01:22:19 +00:00
|
|
|
}
|