Merge pull request #159 from RobLoach/subtext

text: Fix TextSubtext() address bounding
This commit is contained in:
Rob Loach
2022-01-16 18:20:47 -05:00
committed by GitHub
2 changed files with 41 additions and 15 deletions

View File

@@ -291,63 +291,68 @@ RLCPPAPI inline unsigned int TextLength(const std::string& text) {
* Get text length, checks for '\0' ending
*/
RLAPI inline std::string TextSubtext(const std::string& text, int position, int length) {
return TextSubtext(text.c_str(), position, length);
return ::TextSubtext(text.c_str(), position, length);
}
/**
* Replace text string (WARNING: memory must be freed!)
*/
RLAPI inline std::string TextReplace(const std::string& text, const std::string& replace, const std::string& by) {
return TextReplace(text.c_str(), replace.c_str(), by.c_str());
char* output = ::TextReplace((char*)text.c_str(), replace.c_str(), by.c_str());
if (output != NULL) {
std::string stringOutput(output);
free(output);
return stringOutput;
}
return "";
}
/**
* Insert text in a position (WARNING: memory must be freed!)
*/
RLAPI inline std::string TextInsert(const std::string& text, const std::string& insert, int position) {
return TextInsert(text.c_str(), insert.c_str(), position);
}
/**
* Append text at specific position and move cursor!
*/
RLAPI inline void TextAppend(const std::string& text, const std::string& append, int *position) {
return TextAppend(text.c_str(), append.c_str(), position);
char* output = ::TextInsert(text.c_str(), insert.c_str(), position);
if (output != NULL) {
std::string stringOutput(output);
free(output);
return stringOutput;
}
return "";
}
/**
* Find first text occurrence within a string
*/
RLAPI inline int TextFindIndex(const std::string& text, const std::string& find) {
return TextFindIndex(text.c_str(), find.c_str());
return ::TextFindIndex(text.c_str(), find.c_str());
}
/**
* Get upper case version of provided string
*/
RLAPI inline std::string TextToUpper(const std::string& text) {
return TextToUpper(text.c_str());
return ::TextToUpper(text.c_str());
}
/**
* Get lower case version of provided string
*/
RLAPI inline std::string TextToLower(const std::string& text) {
return TextToLower(text.c_str());
return ::TextToLower(text.c_str());
}
/**
* Get Pascal case notation version of provided string
*/
RLAPI inline std::string TextToPascal(const std::string& text) {
return TextToPascal(text.c_str());
return ::TextToPascal(text.c_str());
}
/**
* Get integer value from text (negative values not supported)
*/
RLAPI inline int TextToInteger(const std::string& text) {
return TextToInteger(text.c_str());
return ::TextToInteger(text.c_str());
}
} // namespace raylib

View File

@@ -58,6 +58,27 @@ int main(int argc, char *argv[]) {
assert(files.size() > 3);
}
// raylib::TextReplace()
{
std::string input = "Hello World!";
std::string output = raylib::TextReplace(input, "World", "Moon");
assert(output == "Hello Moon!");
}
// raylib::TextInsert()
{
std::string input = "Hello World!";
std::string output = raylib::TextInsert(input, "Good!", 0);
assert(output == "Good! World!");
}
// raylib::TextSubtext()
{
std::string input = "Hello World!";
std::string output = raylib::TextSubtext(input, 6, 5);
assert(output == "World");
}
// Sound
{
raylib::Wave wave(path + "/resources/weird.wav");