Posted to tcl by mookie at Fri Sep 20 00:00:45 GMT 2024view raw
- if I am to read a line from text file, I encounter the issue where it seems to detect % at range positions where, it doesn't exist...
- ranges 23 25 27 29 don't hold the value % and so shouldn't trigger my switch case
- <legend>%_frame_title_%</legend>
- I can add a break clause, which I ultimately need to do, but still confusing to why is this switch triggering.
- mookie@cuddles:~/~scrap/~tcl $ tclsh hexScope.ix
- my line in base16: 3c6c6567656e643e255f6672616d655f7469746c655f253c2f6c6567656e643e
- my line in base32: <legend>%_frame_title_%</legend>
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- I found my % @ 8
- String is: %_frame_title_%</legend>
- Now lets see if the next character to see if it has _
- found _
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- nothing found
- I found my % @ 22
- String is: %</legend>
- Now lets see if the next character to see if it has _
- _ not found
- What about my previous character, was that a _?
- indeed my previous character is a _ @ 21
- nothing found
- I found my % @ 24
- String is: /legend>
- Now lets see if the next character to see if it has _
- _ not found
- What about my previous character, was that a _?
- indeed my previous character is a _ @ 23
- nothing found
- I found my % @ 26
- String is: egend>
- Now lets see if the next character to see if it has _
- _ not found
- What about my previous character, was that a _?
- indeed my previous character is a _ @ 25
- nothing found
- I found my % @ 28
- String is: end>
- Now lets see if the next character to see if it has _
- _ not found
- What about my previous character, was that a _?
- indeed my previous character is a _ @ 27
- nothing found
- I found my % @ 30
- String is: d>
- Now lets see if the next character to see if it has _
- _ not found
- What about my previous character, was that a _?
- indeed my previous character is a _ @ 29
- nothing found
- >> 8 21 23 25 27 29
- ###### CODE #######
- # set myFile [open $base32_myFile]
- # set myFile [open "./timezone.craft"]
- # set lines [split [read $myFile] "\n"]
- # close $myFile
- set lines "<legend>%_frame_title_%</legend>"
- foreach line $lines {
- set x_pos 0
- set y_pos 1
- set z_pos 2
- set a_pos 3
- set list ""
- set located 0
- set i 0
- set string_length [string length $line]
- puts "\n"
- puts "my line in base16: [binary encode hex $line]"
- puts "my line in base32: $line "
- for {set z 0} {$z < $string_length} {incr z} {
- switch [binary encode hex [string range $line $x_pos $x_pos]] {
- 25 { puts "I found my % @ $z"
- switch $located {
- 0 {
- lappend list $z
- }
- }
- puts "String is: [string range $line $z end]"
- puts "Now lets see if the next character to see if it has _"
- incr i
- switch [binary encode hex [string range $line $y_pos $y_pos]] {
- 5f {
- puts "found _ "
- incr x_pos
- incr y_pos
- }
- default {
- puts "_ not found"
- puts "What about my previous character, was that a _?"
- incr x_pos -1
- switch [binary encode hex [string range $line $x_pos $x_pos]] {
- 5f {
- puts "indeed my previous character is a _ @ [expr $z-1]"
- lappend list [expr $z-1] ;# append the previous position
- }
- default {
- puts "it was not"
- incr x_pos 2
- break
- }
- } ;# end switch
- }
- } ;# end switch
- }
- default {
- puts "nothing found"
- incr x_pos
- incr y_pos
- }
- } ;# end switch
- incr i
- switch [string range $line $x_pos $y_pos] { "" { break } }
- }
- puts ">> $list"
- } ;# end foreach
Comments
Posted by mookie at Fri Sep 20 00:22:12 GMT 2024 [text] [code]
Replace: switch [binary encode hex [string range $line $x_pos $x_pos]] { 5f { puts "indeed my previous character is a _ @ [expr $z-1]" lappend list [expr $z-1] } default { puts "it was not" break } with switch [binary encode hex [string range $line $y_pos $y_pos]] { 5f { puts "indeed my previous character is a _ @ [expr $z-1]" lappend list [expr $z-1] } default { puts "it was not" break } As I was subtracting $x_pos by minus one, it would than hunt backwards, find the same result, than loop.. strange.