Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/07/2021 in all areas

  1. Here's the underlying issue with text files. Extended ANSI uses one byte per character and has 128 "upper" characters codes [0x80, 0xFF] which are assigned to a set of characters defined by the codepage in use. The codepage is not explicit and this is a problem for information interchange. Unicode has a very large character set encompassing all glyphs ever used by humans. The range of Unicode characters is [0x000000, 0x10FFFF] which is 1 114 112 possible characters! Obviously an Unicode character (a codepoint) must use something larger than one byte to represent, contrary to previous codepages. This is where encoding enters the scene. A useful encoding is UTF8 which uses sequences of 1 to 4 bytes to represent a character. See UTF8 to understand how this encoding works. The lower part of ANSI is mapped verbatim to the first 128 Unicode codepoints. In UTF8, a byte > 0x7F introduces a sequence one more than one byte and this sequence has to conform to UTF8 encoding. This is what FileGetEncoding tries to determine. The word "España" has different representations in Windows Occidental codepage and UTF8: ANSI Occidental codepage 1252 E s p a ñ a 45 73 70 61 F1 61 UTF8 (NoBOM) E s p a ñ a ┌─┴─┐ 45 73 70 61 C3 B1 61 UTF8 (BOM) E s p a ñ a ┌─┴─┐ EF BB BF 45 73 70 61 C3 B1 61 └──┬───┘ BOM The optional BOM (Byte Order Mark) serves as a special marker to help distinguish UTF8 from byte codepages. If you FileOpen a file with the first content without specifying a mode, AutoIt will try to find in the first 64k bytes if there are invalid UTF8 sequences. If found the file will be open as ANSI, else UTF8. The sequence 0xF1 0x61 is an invalid UTF8 sequence, hence file is treated as ANSI. If a file with the second example is mistakenly open as ANSI it would display as "Espaïa" which is probably not what users want. If an UTF8 BOM is found, it is ignored but the file is treated as UTF8 without further examination. EDIT: The file you provided is empty, hence will by default be considered as UTF8 w/o BOM.
    3 points
  2. Jos

    nix

    Please go somewhere else when you can't behave and am dumb enough to report this and remove all your post. *click*
    2 points
  3. Danp2

    nix

    Glad you found a solution that works for you. FWIW, the script you posted is useless because we can't actually run it against a live website. P.S. I refuse to work harder than you to solve your problem. 😉
    2 points
  4. Multi column searchIn this example a ListView Combo control is used to define search filters. The main ListView is a custom drawn and virtual ListView. Searching and sorting is based on array indexes (1d arrays of integers). ListView ComboIn the ListView Combo control in the image, a search is defined for rows that matches search filters in 3 columns: 2 x's in the Strings column, dates in the range 2015 - 2019 in the Dates column, and 2 consecutive 5 digits in the Floats column. Note that the rows in the ListView Combo corresponds to the columns in $g_aArray and in the main ListView. There are 5 columns in the ListView Combo: Col is the column index in $g_aArray/main ListView The Checkbox is used to enable/disable a search filter Column is the column name in the main ListView Ord is the order of the search filter. The order is filled in automatically when a search filter is enabled and a search string is entered. The order is cleared on a disabled search filter or an empty search string. RegEx indicates RegEx or Normal search Click the Checkbox to switch The Search string column contains search strings that are entered through an Edit control. Click to open the Edit control. Move the mouse out of the Edit control to close it. Note the order of the 3 search filters in the image. The Strings column with order 0 is the first and most significant search filter. The Dates column with order 1 is the next search filter. The Floats column with order 2 is the last and least significant search filter. Rule: For search filters provided with an order, you can only change the least significant search filter (with the highest order). If you want to change the order of the Strings and Floats search filters so that Floats gets order 0 and Strings order 2, you must first disable all 3 search filters in this order: Floats, Dates, Strings. Click the Checkbox in first column to disable the search filters. Then you have to enable the 3 search filters again in this order: Floats, Dates, Strings. Performance considerations are the reason for this rule. Because the search is an incremental search, it's expected to be very dynamic and responsive. There must be no delays if you e.g. adds or removes a character in a search string. Therefore, it's important that only the least significant search filter can be changed. If only the least significant search filter can be changed, only one search and one sort must be recalculated. If it was possible to update the search string in the most significant search filter then both the search and the sort would have to be recalculated for all search filters. In this example with 6 columns in $g_aArray and main ListView, 6 search filters are possible. If all 6 search filters had to be recalculated for both the search and the sort, then it would certainly cause a significant delay. Use the Reset button to completely reset all search filters. Main ListViewThe main ListView uses two different WM_NOTIFY message handlers: WM_NOTIFY_All is used to display all rows in $g_aArray when no search filter is applied. WM_NOTIFY_Search is used to display the matching rows in $g_aArray when one or more search filters are applied. LVN_GETDISPINFO code in WM_NOTIFY_All: Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) Local Static $tText = DllStructCreate( "wchar Text[50]" ), $pText = DllStructGetPtr( $tText ) $tText.Text = $g_aArray[$g_aIndex[($g_iSortDir=$HDF_SORTUP?$tNMLVDISPINFO.Item:$g_iRows-1-$tNMLVDISPINFO.Item)]][$tNMLVDISPINFO.SubItem] $tNMLVDISPINFO.Text = $pText Return Note usage of the sort index $g_aIndex: $g_aArray[$g_aIndex[($g_iSortDir=$HDF_SORTUP?$tNMLVDISPINFO.Item:$g_iRows-1-$tNMLVDISPINFO.Item)]] LVN_GETDISPINFO code in WM_NOTIFY_Search: Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If Not ( $g_aSearchCols[$tNMLVDISPINFO.SubItem] == "" ) Then Return ; Skip $g_aSearchCols Local Static $tText = DllStructCreate( "wchar Text[50]" ), $pText = DllStructGetPtr( $tText ) $tText.Text = $g_aArray[$g_aSearchRows[$g_aSearchIndex[($g_iSortDir=$HDF_SORTUP?$tNMLVDISPINFO.Item:$g_iSearchRows-1-$tNMLVDISPINFO.Item)]]][$tNMLVDISPINFO.SubItem] $tNMLVDISPINFO.Text = $pText Return Note the If statement that skips columns, which are subsequently drawn with custom draw code. Usage of the search index $g_aSearchRows (see below) and the sort index $g_aSearchIndex (see below): $g_aArray[$g_aSearchRows[$g_aSearchIndex[($g_iSortDir=$HDF_SORTUP?$tNMLVDISPINFO.Item:$g_iSearchRows-1-$tNMLVDISPINFO.Item)]]] The custom draw code in WM_NOTIFY_Search that shows the part of a subitem text that exactly matches the search string on a cyan or yellow background is similar to the custom draw code here. Main LoopThe interesting messages in the main loop regarding multi column search are $g_idComboListViewSubItem0,3,4, $idExtractRowsBySearchFilter and $idListViewSort. $g_idComboListViewSubItem0,3,4 handles changes to a search filter made through the ListView Combo control in columns 0, 3, and 4. Rows that match the search filter are extracted from $g_aArray through a $idExtractRowsBySearchFilter message. Finally, the rows are sorted through a $idListViewSort message. SearchingCode to extract the rows that match a search filter is implemented this way for a RegEx search: For $i = 0 To $iSearchRowsAll - 1 If StringRegExp( $g_aArray[$aSearchRowsAll[$i]][$g_iCLVRow], $sSearch ) Then $g_aSearchRows[$g_iSearchRows] = $aSearchRowsAll[$i] $g_iSearchRows += 1 EndIf Next For the first search filter with order 0 in the image $iSearchRowsAll = $g_iRows. And $aSearchRowsAll = $g_aIndex as calculated for the last column (the current sort column) in the main ListView. $g_iSearchRows is the number of matching rows and $g_aSearchRows is an index of the matching rows. For the last search filter with order 2 in the image $iSearchRowsAll = $g_iSearchRows as calculated for the previous search filter with order 1. And $aSearchRowsAll = $g_aSearchIndex (see below) also as calculated for the previous search filter with order 1. SortingSorting the rows that match a search filter is performed this way: $g_tIndex = FAS_Sort2DArrayAu3( $g_aArray, $aCompare, $g_aSearchRows, $g_iSearchRows ) AccessVariables01( IntStructToArraySearchMtd, $g_aSearchIndex ) $g_aSearchRows and $g_iSearchRows are passed to FAS_Sort2DArrayAu3() as parameters. FAS_Sort2DArrayAu3() returns a sort index as a DllStruct, which is converted to a 1d array of integers in $g_aSearchIndex. $g_aSearchIndex is the sort index for rows extracted through a search filter. FAS_Sort2DArrayIndexFunc() performs the sorting when the two additional parameters are passed to FAS_Sort2DArrayAu3(). This is the first part of FAS_Sort2DArrayIndexFunc() to sort strings: Func FAS_Sort2DArrayIndexFunc( $aArray, $aCompare, $aSearchRows, $iSearchRows ) Local $iRows = $iSearchRows, $tIndex = DllStructCreate( "uint[" & $iRows & "]" ), $pIndex = DllStructGetPtr( $tIndex ) Static $hDll = DllOpen( "kernel32.dll" ) Local $c, $a, $lo, $hi, $mi If $aCompare[0][1] Then ; Sorting by one column of strings $c = $aCompare[0][0] $a = $aCompare[0][2] For $i = 1 To $iRows - 1 $lo = 0 $hi = $i - 1 Do $mi = Int( ( $lo + $hi ) / 2 ) Switch StringCompare( $aArray[$aSearchRows[$i]][$c], $aArray[$aSearchRows[DllStructGetData($tIndex,1,$mi+1)]][$c] ) * $a Case -1 $hi = $mi - 1 Case 1 $lo = $mi + 1 Case 0 ExitLoop EndSwitch Until $lo > $hi DllCall( $hDll, "none", "RtlMoveMemory", "struct*", $pIndex+($mi+1)*4, "struct*", $pIndex+$mi*4, "ulong_ptr", ($i-$mi)*4 ) DllStructSetData( $tIndex, 1, $i, $mi+1+($lo=$mi+1) ) Next The very last code box in the Main ListView section above shows how to extract a row from $g_aArray, taking into account both $g_aSearchRows and $g_aSearchIndex. Miscellaneous That's not correct. Starting with Windows 7, all the different parts that make up a listview item or subitem (checkbox, icon, subicon, label, sublabel, left and top margins) have the same size. Only older Windows versions use other sizes. Only very few Windows styles will change these sizes on Windows 7 and later. Code MultiColumnSearch.7z I'll probably add a few more posts in relation to these examples. Then I'll include all the examples in the 7z-file at bottom of first post.
    2 points
  5. Or use this as an opportunity to define the process/steps that are causing you to copy and paste so often, and automate them. Kill two birds with one stone, without having to re-engineer your keyboard keys.
    1 point
  6. jugador

    websocket window7

    @argumentum I am not coder by profession so finding solution on my own is impossible. but I will do post if I find anything interesting but rubbish to fellow coder. This a command line tool written in Rust https://github.com/vi/websocat
    1 point
  7. jchd

    ASC wrong number

    ; sample Unicode strings in AutoIt encoding (UCS2) Local $a = [ _ "All lower ASCII here!", _ "Some characters ¼½¾ÀÁÇÖæÿ in upper ANSI 1252", _ "Some characters > 0xFF: Μεγάλο πρόβλημα" _ ] For $s In $a ConsoleWrite('"' & $s & '"' & " contains " & (StringRegExp($s, "^[\x00-\x7F]*$") ? "" : "NOT ") & "only lower ASCII" & @LF) ConsoleWrite('"' & $s & '"' & " contains " & (StringRegExp($s, "[\x80-\xFF]") ? "some" : "NO ") & "upper ASCII" & @LF) ConsoleWrite('"' & $s & '"' & " contains " & (StringRegExp($s, "[\x{100}-\x{FFFF}]") ? "" : "NO ") & "characters > 0x100" & @LF) Next
    1 point
  8. Danp2

    nix

    The admins may disagree, but the only thing I see to report here is that you deleted all of your prior posts. 🙄
    1 point
  9. If you look at the _SQL_Startup() function, you will see that it returns a new connection object each time it is called. All of the subsequent function calls, that require a connection object, allow you to pass whichever connection object you want to use. So to manage multiple connections, you need to store the connection objects created by _SQL_Startup() and use the appropriate object when you call the functions that require it. Most of the examples use "-1" for the connection object. -1 means to use the last connection object that was successfully created by _SQL_Startup(). Since only one connection is being used in the examples, -1 works fine. All of those examples could have also used the actual value return by the _SQL_Startup() function, $oADODB. Note: This assumes that the UDF you are referring to is the _sql.au3 UDF created by ChrisL. If you are using a different UDF, you need to identify which one.
    1 point
  10. jchd

    ASC wrong number

    The Unicode codepoint of ć is 0x107, that is decimal 263, not 262. ConsoleWrite(AscW("ć") & @LF)
    1 point
  11. Danp2

    ASC wrong number

    Have you looked into using AscW() instead of Asc()?
    1 point
  12. I don't understand your issue. FileGetEncoding() tells you what encoding was used when the file was opened. If FileGetEncoding() used a file name or a handle gotten from an explicit FileOpen without an encoding flag, then the encoding was determined using a set of predefined rules. Keep in mind that FileGetEncoding, when supplied with a file name, still opens the file. Because UTF8 no BOM can read/write an ANSI encoded file. Why don't you discuss the problem you are trying to solve instead of the solution that you've come up with? Maybe there's a better way to do whatever it is you are trying to do.
    1 point
  13. You need to escape your first quote Local $sCommand = '^"' & @ScriptDir etc... A double quote also appear to work, I believe this is what @argumentum meant above. Local $sCommand = '""' & @ScriptDir etc...
    1 point
  14. Also for fun but with StringRegExpReplace: #include <Array.au3> Local $string = "<a>1</a><b>2</b><c>3</c><d>4</d><e>5</e>|<a>1-1</a><b>2-1</b><c>3-1</c><d>4-1</d><e>5-1</e>|<a>1-2</a><b>2-2</b><c>3-2</c><d>4-2</d><e>5-2</e>|" $ret = StringRegExpReplace($string, ".*<a>([^<]+)</a>[^\|]+<e>5-1</e>.*", "$1") MsgBox(0, '', $ret)
    1 point
  15. For a bit of versatility (and for fun) #include <Array.au3> Local $string = "<a>1</a><b>2</b><c>3</c><d>4</d><e>5</e>|<a>1-1</a><b>2-1</b><c>3-1</c><d>4-1</d><e>5-1</e>|<a>1-2</a><b>2-2</b><c>3-2</c><d>4-2</d><e>5-2</e>|" $var = "b" $if = "5-2" Local $aArray = StringRegExp($string, '<' & $var & '>(.{1,3})</' & $var & '>[^\|]*<e>' & $if & '</e>', 1) _ArrayDisplay($aArray)
    1 point
×
×
  • Create New...