Errors, bugs, questions - page 2461

 
fxsaber:

Could you elaborate on this point?

Below is my subjective opinion, if I'm wrong somewhere, I'd be happy to help.


StringLen used to work O(n) until the first NULL character (0x0000) in the string, now it works O(1).
String length could always be truncated via StringSetCharacter(str, pos, 0x00), but they introduced StringSetLength for some reason.

Most likely, the task of code acceleration when working with strings was solved.
The task of speeding up the code was solved and nobody cares that half of the function now handles NULL characters in string and the other half does not.

#define  PRINT(x) Print(#x, ":", string(x))

void OnStart(){  
   string str = "123456789";
   PRINT(str);
   PRINT(StringLen(str));
   
   PRINT(StringSetCharacter(str, 7, 0x00));
   PRINT(StringLen(str));
   
   str += "\x00" + str;
   PRINT(StringLen(str));
   
   str += str;
   PRINT(str);
   PRINT(StringLen(str));
   
   ushort array[];
   PRINT(StringToShortArray(str, array));
   ArrayPrint(array);
   
   PRINT(StringLen(str));
   PRINT(StringLen(ShortArrayToString(array)));
   PRINT(StringLen(ShortArrayToString(array, 0, StringLen(str))));
} 

The result:

2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      str:123456789
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringLen(str):9
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringSetCharacter(str,7,0x00):true
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringLen(str):7
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringLen(str):15
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      str:1234567
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringLen(str):30
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringToShortArray(str,array):31
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      49 50 51 52 53 54 55  0 49 50 51 52 53 54 55 49 50 51 52 53 54 55  0 49 50 51 52 53 54 55  0
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringLen(str):30
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringLen(ShortArrayToString(array)):7
2019.05.15 14:02:11.895 StringFormat_1 (EURUSD,H1)      StringLen(ShortArrayToString(array,0,StringLen(str))):7
 
Sergey Dzyublik:

Below is my subjective opinion, if I'm wrong somewhere, I'd be happy to help.


StringLen used to work O(n) until the first NULL character (0x0000) in the string but now it works O(1).
String length could always be truncated via StringSetCharacter(str, pos, 0x00), but they introduced StringSetLength for some reason.

Most likely, the analyzer solved the task of code acceleration when working with strings.
The task of speeding up the code was solved and nobody cares that half of the function now handles NULL characters in string and the other half does not.


The result:

Please restrain your emotions.
The next time you use foul language, you'll have to get banned - we're not in a pub. And it's no longer fashionable to swear in a pub.
 
Sergey Dzyublik:

StringLen used to work O(n) until the first NULL character (0x0000) in the string, now it works O(1)

Just partially fixed bugs ... why not!? In my memory StringLen always worked correctly (at least in x32)
 
Sergey Dzyublik:
To the developers:
Please add the ability to specify forced code generation for the default assignment operator (copy constructor):

It's a bit complicated. It is easier to use the default constructor analogy:

1) any assignment operator overrides the default assignment operator

2) any copy operator overrides the default copy operator

 
A100:
Just partially corrected mistakes ... why not!?

Because MQL has no consistent idea when dealing with strings with NULL characters this is the problem.
For instance, StringToShortArray supports NULL characters in a string while the inverse function ShortArrayToString does not...

As a result, more time is spent on catching bugs and searching for workarounds rather than on solving particular tasks.

 
A100:

It's a bit complicated. It is easier to use the default constructor analogy:

1) any assignment operator overrides the default assignment operator

2) any copy operator cancels the default copy operator

I don't need undo; I need a forced generation on the contrary.
MQL has no functionality for deep copy of complex types, and in assignment operator and copy constructor they are implemented by default.

 
Sergey Dzyublik:

Since there is no consistent idea in MQL when dealing with strings with NULL characters, this is the problem.
For example, StringToShortArray supports NULL characters in a string, while its inverse function ShortArrayToString does not...

On the one hand yes, on the other hand it is explicitly stated in the Documentation: "or until terminal 0 is met".

 
Sergey Dzyublik:
Well, it's kind of unclear why the zero lines from the pluses were dragged in the first place.
 
A100:

On the one hand yes, on the other hand it is explicitly stated in the Documentation(that it does not)

AndStringToShortArray says the same thing:

 Количество элементов массива для копирования. Определяет длину результатной строки. По умолчанию -1, что означает копирование до конца массива, либо до встречи терминального 0.

However, this does not prevent it from adequately handling NULL characters in the string.

 
Hello. The MT5 mobile version is not connecting to my Alpari broker. What is the problem? Will this be fixed at some point?
Reason: