Page 1 of 2

WZstring. QString replacement. Need community help.

Posted: 07 Mar 2018, 22:26
by moltengear
I understand that QT is very good, but there are several reasons to refuse this.
1) The compilation of the project is complicated.
2) It is necessary to further teach the framework to fans of this stunning game.
3) There is a faster Javascript engine V8.
4) The Qt installation file already has 2 gigabytes.

This is redundant for simple games.
So I decided to create a WZstring class. I have already implemented a lot at the moment.
I want to make it very similar to javascript.
But I want to consult you. What kind of unicode to implement?
The PhysicsFS library works with the UTF8 format.
I also want to make read and write functions similar to Node.
What to add?

At this point, the class uses a simple string. I'll upload a test version soon.

Re: WZstring. QString replacement. Need community help.

Posted: 07 Mar 2018, 23:07
by Berg
From what I hear QT might be no more soon.

Re: WZstring. QString replacement. Need community help.

Posted: 07 Mar 2018, 23:41
by pastdue
This is already in-progress, including a WzString class that replicates all necessary QString functionality with proper Unicode support. It's not yet in master, but it's well under-way.

Re: WZstring. QString replacement. Need community help.

Posted: 07 Mar 2018, 23:50
by moltengear
It is very good! Can I view the code?

Re: WZstring. QString replacement. Need community help.

Posted: 08 Mar 2018, 00:10
by Berg
https://github.com/Warzone2100/warzone2100

Edit:
Qt dependence reduction is located in one of pastdue's branches in here.

Re: WZstring. QString replacement. Need community help.

Posted: 15 Mar 2018, 01:08
by moltengear
I think this dependence limits development. I downloaded. I'll study the code.
I just renamed my class to the WzString. And yet, are you more inclined to analogy of Qt than to javascript?

Re: WZstring. QString replacement. Need community help.

Posted: 15 Mar 2018, 02:22
by pastdue
There's more that I have yet to push to my branch. Those changes will be coming soon.

The goal is to move the core over to C++, the C++ stdlib, & reasonable (small, cross-platform, stable, performant, easy to build) libraries. In this first phase, that is being done with minimized changes to the existing code so as to not introduce new bugs. Instead, the hard work is being done in the compatibility layers that replicate the old Qt class behavior based on the Qt documentation (like WzString) - but without requiring a giant dependency.

After the core has gone through this process, which is proceeding nicely, we can look at options for the scripting engine. V8, IMHO, is not a likely choice, as it doesn't fit at least two of the major qualifications for integrating third-party libraries ("small" and "easy to build"), and there appear to be better choices for our purposes.

Re: WZstring. QString replacement. Need community help.

Posted: 15 Mar 2018, 03:11
by moltengear
I found two files.
WzString.h
WzString.cpp


Can you make examples of using this class with comments?
All the implemented features at the moment in the console application.
This will also be a guide for use.

Code: Select all

int main()
{
WzString str;

cout<< 

system("pause");
}
I have several features of my WzString class.
I will add features and upload versions for discussion.

Re: WZstring. QString replacement. Need community help.

Posted: 15 Mar 2018, 03:22
by pastdue
The goal is to produce a largely drop-in replacement for QString for Warzone, not to write a C++ string class with a new API (and not to replicate *all* of QString since Warzone doesn't use or need all of it). We'd be using std::string directly if we weren't intending to: (a) provide an easy drop-in replacement for QString (necessitating minimal changes to other code), (b) do a few UTF-8 conversion tasks (for which a simple wrapper type of std::string makes some sense).

In general, we're trying to keep everything as "C++"-like as we can.

Re: WZstring. QString replacement. Need community help.

Posted: 17 Mar 2018, 23:56
by moltengear
That's as promised. I'll create a header file after everything works fine. :)
main.cpp
(11.98 KiB) Downloaded 107 times
There you will also find various examples of using the class.
You can search for such combinations that cause an error. I did not find.

I also created two functions for reading and writing a text file. Likewise like in javascript. This is only for UTF16LE.
main.cpp
(1.41 KiB) Downloaded 90 times

Re: WZstring. QString replacement. Need community help.

Posted: 18 Mar 2018, 00:29
by moltengear
This string class behaves like a javascript.
If the javascript is very popular, then it will not be difficult to learn how to use this class.
I renamed the class name back so as not to be confused.
C ++ is preferable, but I think that the speed of development will increase if you use a class similar to such languages as Csharp, Java, javascript.
I worked very much. There is still half of the work.
There are not enough operators =+ and ==.
Maybe you will find mistakes.
It's almost possible to add all the functions of a C ++ string.
This is not the final version, it's only an alpha version. I'm preparing a beta version, your help is very important. :P

Re: WZstring. QString replacement. Need community help.

Posted: 18 Mar 2018, 02:50
by pastdue
I appreciate what you are doing, but your class does not properly handle Unicode, which the WzString class in the branch above already does.

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.

Re: WZstring. QString replacement. Need community help.

Posted: 18 Mar 2018, 14:18
by Per
I don't really like the idea of us using our own, proprietary string class. I think UTF-8 has won the unicode wars, and we use that everywhere for storage. QString uses UTF-16 for weird historical reasons, but that is a dead end. UTF > 8 means lots of unnecessary conversions, where we could just pass a reference, which I dislike. C++11 and above have a lot of really good improvements for string handling, which we lose if we roll our own stuff, including std::to_string() and taking string views rather than making string copies.

I'd rather we just replaced QString with std::string, and added utility functions for the few places where QString has functionality that std::string lacks.

Re: WZstring. QString replacement. Need community help.

Posted: 18 Mar 2018, 15:13
by Cyp
UTF-16 is great because it lets you store any Unicode codepoint in one position. Unless the Unicode consortium does something weird like extending the codepoints past 0xFFFF, which they would never do. Oh, wait…

I haven't looked at the proposed replacement, but I think using std::string with utility functions sounds like a good idea. Perhaps unless the strings need to store colour or font or something as well as text.

Re: WZstring. QString replacement. Need community help.

Posted: 18 Mar 2018, 16:43
by pastdue
The WzString class in my branch is a lightweight wrapper around std::string & stdlib C++11 functionality (with utility functions) for just this reason.

Because std::string does nothing to natively support UTF-8, using std::string methods like `length()` or `size()` or enumerating "characters" very quickly leads to broken UTF-8 (as you'll be enumerating bytes, not code points or graphemes). The lightweight WzString wrapper, to easily integrate with existing code, provides length() (etc) methods that properly handle UTF-8 and match prior behavior handling codepoints. The rest of the utility functions are to ease adopting in the existing code (which currently requires a number of QString behavior quirks).

That's about it. Simple, based on std::string, with the minimal additions / overloads required to properly support UTF-8 & utility functions for current code compatibility.