WZstring. QString replacement. Need community help.

For code related discussions and questions

WZstring. QString replacement. Need community help.

Postby moltengear » 07 Mar 2018, 22:26

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

Re: WZstring. QString replacement. Need community help.

Postby Berg » 07 Mar 2018, 23:07

From what I hear QT might be no more soon.
User avatar
Berg
Regular
Regular
 
Posts: 1977
Joined: 02 Sep 2007, 23:25
Location: Australia

Re: WZstring. QString replacement. Need community help.

Postby pastdue » 07 Mar 2018, 23:41

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

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 07 Mar 2018, 23:50

It is very good! Can I view the code?
You can support me. DOGE wallet - D5GFBVPoa2jcrwJqXyBvcYimnBB6mgHGjT
moltengear
Trained
Trained
 
Posts: 55
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Postby Berg » 08 Mar 2018, 00:10

https://github.com/Warzone2100/warzone2100

Edit:
Qt dependence reduction is located in one of pastdue's branches in here.
Last edited by Berserk Cyborg on 09 Mar 2018, 21:56, edited 1 time in total.
Reason: Add correct link of what the author was asking for.
User avatar
Berg
Regular
Regular
 
Posts: 1977
Joined: 02 Sep 2007, 23:25
Location: Australia

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 15 Mar 2018, 01:08

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

Re: WZstring. QString replacement. Need community help.

Postby pastdue » 15 Mar 2018, 02:22

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

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 15 Mar 2018, 03:11

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

Re: WZstring. QString replacement. Need community help.

Postby pastdue » 15 Mar 2018, 03:22

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

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 17 Mar 2018, 23:56

That's as promised. I'll create a header file after everything works fine. :)
main.cpp
(11.98 KiB) Downloaded 27 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 24 times
Last edited by moltengear on 18 Mar 2018, 00:46, edited 1 time in total.
You can support me. DOGE wallet - D5GFBVPoa2jcrwJqXyBvcYimnBB6mgHGjT
moltengear
Trained
Trained
 
Posts: 55
Joined: 22 Jul 2017, 15:05

Re: WZstring. QString replacement. Need community help.

Postby moltengear » 18 Mar 2018, 00:29

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

Re: WZstring. QString replacement. Need community help.

Postby pastdue » 18 Mar 2018, 02:50

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

Re: WZstring. QString replacement. Need community help.

Postby Per » 18 Mar 2018, 14:18

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.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3745
Joined: 03 Aug 2006, 19:39

Re: WZstring. QString replacement. Need community help.

Postby Cyp » 18 Mar 2018, 15:13

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.
Cyp
Evitcani
Evitcani
 
Posts: 702
Joined: 17 Jan 2010, 23:35

Re: WZstring. QString replacement. Need community help.

Postby pastdue » 18 Mar 2018, 16:43

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

Next

Return to Coding