Page 2 of 2

Re: WZstring. QString replacement. Need community help.

Posted: 18 Mar 2018, 23:18
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 (:

Re: WZstring. QString replacement. Need community help.

Posted: 22 Apr 2018, 21:12
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 160 times

Re: WZstring. QString replacement. Need community help.

Posted: 22 Apr 2018, 22:37
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.

Re: WZstring. QString replacement. Need community help.

Posted: 23 Apr 2018, 01:31
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.

Re: WZstring. QString replacement. Need community help.

Posted: 23 Apr 2018, 01:42
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.

Re: WZstring. QString replacement. Need community help.

Posted: 23 Apr 2018, 01:53
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

Re: WZstring. QString replacement. Need community help.

Posted: 24 Jul 2018, 00:14
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?

Re: WZstring. QString replacement. Need community help.

Posted: 03 Nov 2018, 14:50
by moltengear
I changed the name. I added the ability to read and write files to the class. Only ANSI for the moment.

Re: WZstring. QString replacement. Need community help.

Posted: 03 Nov 2018, 14:55
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.

Re: WZstring. QString replacement. Need community help.

Posted: 01 Dec 2018, 20:19
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;
}

Re: WZstring. QString replacement. Need community help.

Posted: 21 Jan 2019, 04:02
by vexed
Thought that we already had a replacement for QString?

Re: WZstring. QString replacement. Need community help.

Posted: 21 Jan 2019, 13:07
by moltengear
I lost my former motivation. Who is interested in?

Re: WZstring. QString replacement. Need community help.

Posted: 21 Jan 2019, 17:52
by pastdue
vexed wrote:
21 Jan 2019, 04:02
Thought that we already had a replacement for QString?
Yep.

Re: WZstring. QString replacement. Need community help.

Posted: 14 Mar 2019, 20:18
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.

Re: WZstring. QString replacement. Need community help.

Posted: 14 Mar 2019, 20:34
by moltengear
You may need to change to your version windows sdk 10.0. I used the 10.0.17763.0 version.