Yes, the Javascript engine creates for your example a byte array with correct byte size and property length contains the correct number of bytes for the array. But array property length is not equal the string length for your example. It is the size of the array, not the string length. Try following in a HTML file:
Code: Select all
<script type="text/javascript">
var Text1="zero\0zero";
alert("Text 1 is: "+Text1);
alert("Text 1 length is: "+String(Text1.length));
var Text2 = "Text is: "+Text1+" and text length is: "+String(Text1.length);
alert(Text2);
alert("Text 2 length is: "+String(Text2.length));
</script>
and you will see only "
Text 1 is: zero" in the first message box and "
Text 1 length is: 9" in the second message box.
The third alert outputs also "
Text is: zero" because the strings are correct concatenated, but the NULL character inside the string variable is the terminating character for the print. This is confirmed by the fourth message showing "
Text 2 length is: 40".
And yes, the clipboard buffer is just a dynamic memory buffer which can hold also binary data. The clipboard is not a string array, it is a byte array and therefore can contain all values from 0 to 255 which are not special interpreted (normally) as the bytes in a string array are when accessing the data in the array.
UltraEdit.clipboardContent = UltraEdit.clipboardContent;
I'm not wondering that this clears the clipboard content because the clipboard is a dynamically allocated memory buffer using
malloc() and
free() in 'C' or
new and
delete in C++ (which uses in the background also malloc() and free()). So when you assign (=copy) a buffer to the clipboard, the first function called is free() to release the existing memory buffer of the (active) clipboard. Now the clipboard buffer pointer is NULL and therefore the next function calls for getting the size in bytes of the new data, allocating the buffer with required byte size from heap and copying the data must fail here. So your line is the same as
UltraEdit.clearClipboard(); with the only difference that you test also the error handling of the functions used in the background for handling dynamic memory buffers.
However, the problem you have here is not the Javascript engine and how it handles bytes with value 0. The problem is that UltraEdit stops character copying from the clipboard buffer to the file buffer in text mode on first ocurrence of a NULL byte which is in my point of view a correct behavior because NULL bytes are binary bytes and should not exist in a text file (except in UTF-16 files). For example if you create a new file, write some text, switch to hex edit mode, replace 1 character with 00, select all bytes in hex edit mode, turn off hex editing and paste now the clipboard content into the file in text edit mode, UltraEdit pastes only the text left the NULL byte. But when you now switch again into hex edit mode and paste the clipboard content, you will see that the clipboard contains really all bytes because all of them are inserted in hex edit mode.