WZstring. QString replacement. Need community help.

For code related discussions and questions
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: WZstring. QString replacement. Need community help.

Post by NoQ »

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
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

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 440 times
Last edited by moltengear on 23 Apr 2018, 00:10, edited 1 time in total.
pastdue
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 339
Joined: 13 Aug 2017, 17:44

Re: WZstring. QString replacement. Need community help.

Post by pastdue »

@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.
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

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.
pastdue
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 339
Joined: 13 Aug 2017, 17:44

Re: WZstring. QString replacement. Need community help.

Post by pastdue »

@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.
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

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
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

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?
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

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 391 times
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

Example usage.

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");
}
wstrpie - will be for Unicode.
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

I added functions.
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";
	}
The functions from javascript - slice, search, indexOf, charCodeAt, fromCharCode
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 379 times
User avatar
vexed
Inactive
Inactive
Posts: 2538
Joined: 27 Jul 2010, 02:07

Re: WZstring. QString replacement. Need community help.

Post by vexed »

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.
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

I lost my former motivation. Who is interested in?
pastdue
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 339
Joined: 13 Aug 2017, 17:44

Re: WZstring. QString replacement. Need community help.

Post by pastdue »

vexed wrote: 21 Jan 2019, 04:02 Thought that we already had a replacement for QString?
Yep.
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

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.

Code: Select all

	strpie ht = "afa4352g aga df6fstyy";  
	bool ok;
	cout << ht.toIntTotal(&ok) << endl;   //   43526
	cout << ok << endl;
Removed the second point, if found in the text.
Attachments
strpie_1.1.zip
(8.01 KiB) Downloaded 368 times
User avatar
moltengear
Trained
Trained
Posts: 170
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Post by moltengear »

You may need to change to your version windows sdk 10.0. I used the 10.0.17763.0 version.
Post Reply