Skip to content

Commit

Permalink
Fixed indexing to support utf-8 characters in strings (#91)
Browse files Browse the repository at this point in the history
* Fixed indexing to support utf-8 characters in strings
* Added special characters to matlab_04.m
  • Loading branch information
julianfritzsch authored Mar 21, 2023
1 parent 0865289 commit 798dc01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/io/matlab.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function split_line(mp_line::AbstractString)
isquote(c) = (c == '\'' || c == '"')

function _push_curr_token()
if curr_pos <= length(mp_line)
if curr_pos <= lastindex(mp_line)
curr_token *= mp_line[curr_pos]
end
curr_token = strip(curr_token)
Expand All @@ -238,14 +238,14 @@ function split_line(mp_line::AbstractString)

function _push_curr_char()
curr_token *= mp_line[curr_pos]
curr_pos += 1
curr_pos = nextind(mp_line, curr_pos)
end

curr_pos = 1
while curr_pos <= length(mp_line)
while curr_pos <= lastindex(mp_line)
if is_curr_token_quote
if mp_line[curr_pos] == curr_token[1]
if mp_line[curr_pos-1] == '\\'
if mp_line[prevind(mp_line, curr_pos)] == '\\'
# If we are inside a quote and we see slash-quote, we should
# treat the quote character as a regular character.
_push_curr_char()
Expand Down
4 changes: 2 additions & 2 deletions test/data/matlab_04.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
% case to test matlab quotes
% case to test matlab quotes and special characters

function mpc = matlab_04

mpc.names = {
'Slack Bus 1'
'ɑ Slack Bus '
'Slack \"Bus\" 1'
'Slack '''
''
Expand Down

0 comments on commit 798dc01

Please sign in to comment.