Jump to content

Format strings


Go to solution Solved by JockoDundee,

Recommended Posts

4 hours ago, dmob said:

EDIT: Yooh!! Is this your real data or a made up "string' "?

I have already asked this question myself :lol:.

@XGamerGuide :

Can you post a script snippet where you have assigned this "string" to a variable, meaning something like :

[...]
Local $sString = [your string]
[...]

The string contains quite a mess of single and double quotes. Where does it actually come from ?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

23 minutes ago, XGamerGuide said:

FileRead()

Ok !

I assume, that there are multiple lines. Do they all follow this structure ?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Quote

I assume, that there are multiple lines. Do they all follow this structure ?

I am currently programming a program that compresses an Autoit Script. To do this, each line is split into an array and read out in a loop. For example, to remove a comment with ; my program needs to know whether this character is in a string or not.

Link to comment
Share on other sites

This works on your test case:

#include <Array.au3>

Dim $a_array[0]=[]

$file = FileRead(@ScriptDir & "\" & "text.txt")
$c = Chr(34) ; "
$d = Chr(39) ; '

$getchar = ""
$tmptxt = ""

;StartC, StartD
$sc = 0
$sd = 0

For $x = 1 To StringLen($file)
    $getchar = StringMid($file,$x,1)

    If $getchar = $c And $sd = 0 And $sc = 0 Then
        If StringLen($tmptxt) > 0 Then
            _ArrayAdd($a_array, $tmptxt)
            $tmptxt = ""
        EndIf
        $sc = 1     
    ElseIf $getchar = $d And $sd = 0 And $sc = 0 Then
        If StringLen($tmptxt) > 0 Then
            _ArrayAdd($a_array, $tmptxt)
            $tmptxt = ""
        EndIf
        $sd = 1     
    ElseIf $getchar = $c And $sd = 0 And $sc = 1 Then
        $sc = 0
        $getchar=""
    ElseIf $getchar = $d And $sd = 1 And $sc = 0 Then
        $sd = 0
        $getchar=""
    EndIf

    If $sc = 0 And $sd = 0 Then $tmptxt = $tmptxt & $getchar

Next

if $sc=0 and $sd=0 and StringLen($tmptxt)>0 then _ArrayAdd($a_array, $tmptxt)

For $x=0 to UBound($a_array)-1
    CW($a_array[$x])
Next

Func CW($txt, $crlf = 1)
    Local $nl = ""
    If $crlf = 1 Then $nl = @CRLF
    ConsoleWrite($txt & $nl)
EndFunc   ;==>CW

I haven't tested all cases. 

 

Edit: removed 2 meaningless assignment of the $tmptxt variable.

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

12 minutes ago, XGamerGuide said:

I am currently programming a program that compresses an Autoit Script. To do this, each line is split into an array and read out in a loop. For example, to remove a comment with ; my program needs to know whether this character is in a string or not.

Ok, that at least throws some light into the darkness ;).

Maybe a stupid question, but have you ever taken a look at the functionalities of Tidy ?

9 minutes ago, Dan_555 said:

This works on your test case:

I tried to do something similar using "StringRegExpReplace", but all the quotes are not so easy to handle. You probably finished your solution before @XGamerGuide described the actual goal of his project :).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Just out of curiosity :
What exactly do you intend when you write :

42 minutes ago, XGamerGuide said:

I am currently programming a program that compresses an Autoit Script.

Will the script still be human-readable in the end, or what do you want to achieve by using 'your compression'?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Quote

Will the script still be human-readable in the end, or what do you want to achieve by using 'your compression'?

After compression, the script should only be read by the Autoit interpreter and no longer by programmers. This makes the file smaller

Link to comment
Share on other sites

And why not... guess what ?  :)

#Include <Array.au3>

$s = StringStripWS(FileRead("test.txt"), 2)

; use a replacement character to replace the 'string' parts
$s = StringRegExpReplace($s, '([''"]).*?\1', ChrW(0xFFFD))
; then split
$res = StringSplit(StringTrimRight($s, 1), ChrW(0xFFFD), 3)

_ArrayDisplay($res)

Edit
Simpler but assumes that the non-string parts contain word chars and/or spaces only, one or more (to be adapted if needed)

#Include <Array.au3>

$s = StringStripWS(FileRead("test.txt"), 2)
$res = StringRegExp($s, '([''"]).*?\1(*SKIP)(*F)|[\w\s]+', 3)

_ArrayDisplay($res)

 

Edited by mikell
Link to comment
Share on other sites

16 minutes ago, XGamerGuide said:

After compression, the script should only be read by the Autoit interpreter and no longer by programmers. This makes the file smaller

Then it is more of an Obfuscator, not a Compressor ;).

I don't want to criticize your project, but just reducing the file size is, in my opinion, not a sufficient reason for all the effort.

For example, if I look at one of my larger scripts (4000+ lines and 10+ includes) , it's just 150 KB. In times of Terabyte HDDs this is next to nothing.

If, on the other hand, you want to protect your scripts against access by people with little knowledge, then compiling them as .a3x would be a possible solution. However, it is your spare time and you can do whatever you feel comfortable with :).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

17 minutes ago, mikell said:

And why not... guess what ?  :)

What took you so long ? :D Nice job.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

2 hours ago, XGamerGuide said:

I am currently programming a program that compresses an Autoit Script. To do this, each line is split into an array and read out in a loop. For example, to remove a comment with ; my program needs to know whether this character is in a string or not.

Isn't that (and more) that #AutoIt3Wrapper_Run_Au3Stripper=y would do?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Quote

And why not... guess what ?  :)

Thanks, works great

Quote

For example, if I look at one of my larger scripts (4000+ lines and 10+ includes) , it's just 150 KB. In times of Terabyte HDDs this is next to nothing.

In my program it is also base54 encoded. That makes the file 30% larger after times. I don't want it to take so long to decode.

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...