orbs

_StringInsert fails when insertion point > 65535

4 posts in this topic

#include <String.au3>

Global $iLength = 99999 ; change it to whatever, as long as it's longer than the insert point
Global $iInsert = 65536 ; insert point 65536 => not working, and no @error. change it to 65535 => OK

Global $s1 = _StringRepeat('a', $iLength)
$s1 = _StringInsert($s1, 'b', $iInsert)

ConsoleWrite( _
        '@error = ' & @error & @LF & _
        'Length = ' & StringLen($s1) & @LF & _
        'Char   = ' & StringMid($s1, $iInsert + 1, 1) & @CRLF)

issue is quite simple really, title and code above speaks for itself. i'm just trying to make sure i'm not missing the obvious before submitting a ticket.

issue exists in AutoIt v3.3.12.0 & v3.3.10.2, as well as latest Beta.

issue does not exist in AutoIt v3.3.8.1

there was a major rewrite of this function after v3.3.8.1, but it's now using StringRegExpReplace, which i'm not comfortable with.

Share this post


Link to post
Share on other sites



orbs,

I can confirm the bug. :(>

It seems to be a limitation of the PCRE engine which means that it cannot deal with quantifiers greater than 65535. Here is an illustration:

#include <String.au3>

Global $iLength = 99999
Global $sString = _StringRepeat('a', $iLength)

Global $iInsert = 65535
$sOne = StringRegExpReplace($sString, "(?s)\A(.{" & $iInsert & "})(.*)\z", "$1")
$sTwo = StringRegExpReplace($sString, "(?s)\A(.{" & $iInsert & "})(.*)\z", "$2")
ConsoleWrite($iInsert & " : " & StringLen($sOne) & " - " & StringLen($sTwo) & @CRLF)

Global $iInsert = 65536
$sOne = StringRegExpReplace($sString, "(?s)\A(.{" & $iInsert & "})(.*)\z", "$1")
$sTwo = StringRegExpReplace($sString, "(?s)\A(.{" & $iInsert & "})(.*)\z", "$2")
ConsoleWrite($iInsert & " : " & StringLen($sOne) & " - " & StringLen($sTwo) & @CRLF)
As you can see, the long string is not cut when the $iInsert value is greater than 65535. I will discuss it with the Devs. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this version:

;

; #Function# ===================================================================================================================
; Author ........: Louis Horvath <celeri at videotron dot ca>
; Modified ......: czardas - (re-write for optimization), jchd (removed explicit checks on string parameters)
; ==============================================================================================================================

Func _StringInsert_MOD($sString, $sInsertString, $iPosition)
    ; Retrieve the length of the source string
    Local $iLength = StringLen($sString)
    ; Casting Int() takes care of String/Int, Numbers
    $iPosition = Int($iPosition)
    ; Adjust the position to accomodate negative values (insertion from the right)
    If $iPosition < 0 Then $iPosition = $iLength + $iPosition
    ; Check the insert position is within bounds
    If $iLength < $iPosition Or $iPosition < 0 Then Return SetError(1, 0, $sString)
    ; Insert the string
    Return StringLeft($sString, $iPosition) & $sInsertString & StringRight($sString, $iLength - $iPosition)
EndFunc
Edited by czardas

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

orbs,

And as you can see the problem had already been solved and just awaits a new Beta release. :)

M23

Edited by Melba23
Typo

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now