WZstring. QString replacement. Need community help.

For code related discussions and questions

Re: WZstring. QString replacement. Need community help.

Postby NoQ » 18 Mar 2018, 23:18

taking string views rather than making string copies

...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 (:
User avatar
NoQ
Special
Special
 
Posts: 6156
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 22 Apr 2018, 21:12

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> ?

main utf8toWstring (2).zip
(11.25 KiB) Downloaded 21 times
Last edited by moltengear on 23 Apr 2018, 00:10, edited 1 time in total.
You can support me. DOGE wallet - D5GFBVPoa2jcrwJqXyBvcYimnBB6mgHGjT
moltengear
Trained
Trained
 
Posts: 61
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Postby pastdue » 22 Apr 2018, 22:37

@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.
pastdue
Code contributor
Code contributor
 
Posts: 98
Joined: 13 Aug 2017, 17:44

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 23 Apr 2018, 01:31

pastdue, you said:
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'm experimenting and exploring.
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);


Our class can simplify this way.
Code: Select all
WZstring str = "hello";
str.NewLine();

It looks like C #

C++ string. For example, if you want to do concatenation of different types
Code: Select all
wstring str = "fps ";
str.append(to_string(x));


Our class
Code: Select all
WZstring str = "fps "_ + x;


An example of reading and writing.
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;
}


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.
Last edited by moltengear on 23 Apr 2018, 01:45, edited 1 time in total.
You can support me. DOGE wallet - D5GFBVPoa2jcrwJqXyBvcYimnBB6mgHGjT
moltengear
Trained
Trained
 
Posts: 61
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Postby pastdue » 23 Apr 2018, 01:42

@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.
pastdue
Code contributor
Code contributor
 
Posts: 98
Joined: 13 Aug 2017, 17:44

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 23 Apr 2018, 01:53

You explain how you can use your class, in which cases. I don't understand.

@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.

I'm doing it! Simple class + unicode
You can support me. DOGE wallet - D5GFBVPoa2jcrwJqXyBvcYimnBB6mgHGjT
moltengear
Trained
Trained
 
Posts: 61
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 24 Jul 2018, 00:14

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?
You can support me. DOGE wallet - D5GFBVPoa2jcrwJqXyBvcYimnBB6mgHGjT
moltengear
Trained
Trained
 
Posts: 61
Joined: 22 Jul 2017, 15:05

Previous

Return to Coding