...is great as long as you make sure that the string is not temporary. I'm responsible for dozens of such crashes at work, so i recommend extreme caution and address-sanitized builds every time you do this (:taking string views rather than making string copies
WZstring. QString replacement. Need community help.
Re: WZstring. QString replacement. Need community help.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
I added support for reading and writing text files for utf8 encoding.
Only I didn't test these functions in the Linux and Mac operating systems.
It would be great if someone would test. Because the line break is implemented in different ways.
Mac = "\r"
Linux = "\n"
Windows = "\r" + "\n"
Idiocy!
I didn't implement the conversion in memory.
For example, you need to get data from the Internet.
In what form is it desirable to store?
unsigned char* -> wstring ?
wstring -> unsigned char* ?
unsigned char[]
<vector> ?
Only I didn't test these functions in the Linux and Mac operating systems.
It would be great if someone would test. Because the line break is implemented in different ways.
Mac = "\r"
Linux = "\n"
Windows = "\r" + "\n"
Idiocy!
I didn't implement the conversion in memory.
For example, you need to get data from the Internet.
In what form is it desirable to store?
unsigned char* -> wstring ?
wstring -> unsigned char* ?
unsigned char[]
<vector> ?
Last edited by moltengear on 23 Apr 2018, 00:10, edited 1 time in total.
Re: WZstring. QString replacement. Need community help.
@moltengear: The WZ codebase already has functionality for loading files in different formats, and it works seamlessly across platforms. A string class is not the place for this functionality. Please see the earlier replies in this thread.
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
pastdue, you said:
I remember many years ago I refused C ++ because of the strings in favor of C #.
C++ string. For example, a line break.
Our class can simplify this way.
It looks like C #
C++ string. For example, if you want to do concatenation of different types
Our class
An example of reading and writing.
It is possible to make so that a line break has always been a symbol of "\n".
This is convenient for different operating systems.
In the processing of lines, only one character of the break, and the file is read and written, depending on the operating system. It looks like javascript. It's easy to work with strings. I rather do it.
I'm experimenting and exploring.I do like your ideas surrounding additional operator+ overloads, so we may roll those ideas into WzString to ease future development. And as we go through older code, we can revise it to use them (instead of the Qt-like methods). For now, though, we need a class that is backwards-compatible with existing code.
I remember many years ago I refused C ++ because of the strings in favor of C #.
C++ string. For example, a line break.
Code: Select all
wchar_t p13 = (wchar_t)13;
wchar_t p10 = (wchar_t)10;
std::wstringstream wss;
wss << p13 << p10;
wstring NewLine = wss.str();
wstring str = "hello";
str.append(NewLine);
Code: Select all
WZstring str = "hello";
str.NewLine();
C++ string. For example, if you want to do concatenation of different types
Code: Select all
wstring str = "fps ";
str.append(to_string(x));
Code: Select all
WZstring str = "fps "_ + x;
Code: Select all
int main()
{
wchar_t p13 = (wchar_t)13;
wchar_t p10 = (wchar_t)10;
std::wstringstream wss;
wss << p13 << p10;
wstring newLine = wss.str();
wstring sample;
sample.append(newLine);
sample.append(L"おはよう 林檎 Apple Intel");
sample.append(newLine);
sample.append(newLine);
sample.append(newLine);
sample.append(L"おはよう 林檎 Samsung");
writeFileSync("a_utf16.txt", sample, "utf16le");
wstring strw;
strw = readFileSync("a_utf16.txt", "utf16le");
writeFileSync("b_utf16.txt", strw, "utf16le");
writeFileSync("c_utf8.txt", strw, "utf8");
wstring strw2;
strw2 = readFileSync("c_utf8.txt", "utf8");
writeFileSync("d_utf16.txt", strw2, "utf16le");
writeFileSync("e_utf8.txt", strw2, "utf8");
system("pause");
return 0;
}
This is convenient for different operating systems.
In the processing of lines, only one character of the break, and the file is read and written, depending on the operating system. It looks like javascript. It's easy to work with strings. I rather do it.
Last edited by moltengear on 23 Apr 2018, 01:45, edited 1 time in total.
Re: WZstring. QString replacement. Need community help.
@moltengear: Please review the later replies - the consensus was not to go that direction. We are doing a lightweight wrapper of std::string, with appropriate Unicode support.
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
You explain how you can use your class, in which cases. I don't understand.
I'm doing it! Simple class + unicode@moltengear: Please review the later replies - the consensus was not to go that direction. We are doing a lightweight wrapper of std::string, with appropriate Unicode support.
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
I have an idea. Indeed, it makes sense if this class of strings will be more universal.
That is, to add for the letters compressed textures and the color value. For mobile phones use another compression. Also I used to talk about gui - ImGUI.
But the controls are created in some kind of window. And you can move it all with the mouse.
I found a similar one - nuklear. https://github.com/vurtun/nuklear
It needs to download fonts. Just I will copy the dxt data.
What font to use is preferable?
That is, to add for the letters compressed textures and the color value. For mobile phones use another compression. Also I used to talk about gui - ImGUI.
But the controls are created in some kind of window. And you can move it all with the mouse.
I found a similar one - nuklear. https://github.com/vurtun/nuklear
It needs to download fonts. Just I will copy the dxt data.
What font to use is preferable?
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
I changed the name. I added the ability to read and write files to the class. Only ANSI for the moment.
- Attachments
-
- strpie.zip
- (3.63 KiB) Downloaded 411 times
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
Example usage.
wstrpie - will be for Unicode.
Code: Select all
#include "strpie.h"
int main()
{
strpie str = "hello";
str.NewLine();
str = str + "world";
cout << str << "\n";
str.writeFile("mytext.txt");
strpie str2;
str2.readFile("mytext.txt");
cout << str2 << "\n";
system("pause");
}
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
I added functions.
Also operator overloads.
Comparison operator. Now this type of construction is possible.
The functions from javascript - slice, search, indexOf, charCodeAt, fromCharCode
find() - C++, python
Also operatop +=.
Example
Also operator overloads.
Comparison operator. Now this type of construction is possible.
Code: Select all
strpie str1 = "apple";
strpie str2 = "apple";
if (str1 == str2)
{
std::cout << "TRUE" << "\n";
}
find() - C++, python
Also operatop +=.
Example
Code: Select all
#include <iostream>
#include "strpie.h"
int main()
{
strpie str0 = "apple";
strpie str2 = "apple";
//str0.NewLine();
if (str0 == str2)
{
std::cout << "TRUE" << "\n";
}
else
{
std::cout << "FALSE" << "\n";
}
str0 += " float ";
std::cout << str0 <<"\n";
strpie wg = "hello";
wg.slice(2); // Remove one character from string
std::cout << wg << "\n";
strpie ch;
// ch.fromCharCode(50); // also it is possible
std::cout << "fromCharCode "<< ch.fromCharCode(70) << "\n";
ch = "\"";
std::cout << "charCodeAt "<<ch.charCodeAt() << "\n";
system("pause");
return 0;
}
- Attachments
-
- strpie 1.0.zip
- (29.22 KiB) Downloaded 400 times
Re: WZstring. QString replacement. Need community help.
Thought that we already had a replacement for QString?
/facepalm ...Grinch stole Warzone contra principia negantem non est disputandum
Super busy, don't expect a timely reply back.
Super busy, don't expect a timely reply back.
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
I lost my former motivation. Who is interested in?
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
Here is the corrected version!
I fixed all the warnings. I added the "test" method.
It happens such a situation when important to know that a certain character or word is present in the text.
I also added the ability to convert from string to numbers.
Just like Qt: toInt(), toLongLong(), toFloat(), toDouble()
toIntTotal(), toInt64Total(), toFloatTotal(), toDoubleTotal() - These methods are distinguished by the presence of checks, and all letters in front of numbers are also deleted.
Removed the second point, if found in the text.
I fixed all the warnings. I added the "test" method.
It happens such a situation when important to know that a certain character or word is present in the text.
I also added the ability to convert from string to numbers.
Just like Qt: toInt(), toLongLong(), toFloat(), toDouble()
toIntTotal(), toInt64Total(), toFloatTotal(), toDoubleTotal() - These methods are distinguished by the presence of checks, and all letters in front of numbers are also deleted.
Code: Select all
strpie ht = "afa4352g aga df6fstyy";
bool ok;
cout << ht.toIntTotal(&ok) << endl; // 43526
cout << ok << endl;
- Attachments
-
- strpie_1.1.zip
- (8.01 KiB) Downloaded 382 times
- moltengear
- Trained
- Posts: 170
- Joined: 22 Jul 2017, 15:05
Re: WZstring. QString replacement. Need community help.
You may need to change to your version windows sdk 10.0. I used the 10.0.17763.0 version.