Skip to content

Commit

Permalink
Merge pull request #151 from Banaanae/6Properties
Browse files Browse the repository at this point in the history
Partially fix Insert() and Remove()
  • Loading branch information
Banaanae authored Mar 15, 2024
2 parents 2198695 + c5cca30 commit 98f7363
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
30 changes: 30 additions & 0 deletions convert/4ArrayMethods.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,34 @@ global ArrayMethodsToConvertM := OrderedMap(
"Length"
, "HasKey(Key)" ,
"Has({1})"
, "Insert(Keys)",
"*_InsertAt"
, "Remove(Keys)",
"*_RemoveAt"
)

_InsertAt(p) {
if (p.Length = 1) {
Return "Push(" p[1] ")"
} else if (p.Length > 1 && IsDigit(p[1])) {
for i, v in p {
val .= ", " v
}
Return "InsertAt(" LTrim(val, ", ") ")"

}
}

_RemoveAt(p) { ; TODO: handle Vars
if (p.Length = 1 && p[1] = "") { ; Arr.Remove()
Return "Pop()"
} else if (p.Length = 1 && IsDigit(p[1])) { ; Arr.Remove(n)
Return "RemoveAt(" p[1] ")"
} else if (p.Length = 2 && IsDigit(p[1]) && IsDigit(p[2])) { ; Arr.Remove(n, n)
Return "RemoveAt(" p[1] ", " p[2] " - " p[1] " + 1)"
} else if (p.Length = 2 && IsDigit(p[1]) && p[2] = "`"`"") { ; Arr.Remove(n, "")
Return "Delete(" p[1] ")"
} else {
Return "Pop()" ; TODO: Pop is placeholder, need better fix
}
}
11 changes: 11 additions & 0 deletions tests/Test_Folder/String/Array_ex1.ah1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
arr := ["1","2","3"]

arr.Insert("My Value")
arr.Insert(2, "Val 1", "Val 2", "Val 3", "Val 4", "Val 5")

arr.Remove()
arr.Remove(5)
arr.Remove(4,6)

MsgBox % arr.length()
MsgBox % "1: " arr[1] "`n2: " arr[2] "`n3: " arr[3] "`n4: " arr[4]
11 changes: 11 additions & 0 deletions tests/Test_Folder/String/Array_ex1.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
arr := ["1","2","3"]

arr.Push("My Value")
arr.InsertAt(2, "Val 1", "Val 2", "Val 3", "Val 4", "Val 5")

arr.Pop()
arr.RemoveAt(5)
arr.RemoveAt(4, 6 - 4 + 1)

MsgBox(arr.Length)
MsgBox("1: " arr[1] "`n2: " arr[2] "`n3: " arr[3] "`n4: " arr[4])

0 comments on commit 98f7363

Please sign in to comment.