Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
50eb6e44
Commit
50eb6e44
authored
9 years ago
by
Cristian Maglie
Browse files
Options
Downloads
Patches
Plain Diff
Updated Stream class
parent
980947c4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cores/arduino/Stream.cpp
+38
-33
38 additions, 33 deletions
cores/arduino/Stream.cpp
with
38 additions
and
33 deletions
cores/arduino/Stream.cpp
+
38
−
33
View file @
50eb6e44
...
...
@@ -254,59 +254,64 @@ String Stream::readStringUntil(char terminator)
int
Stream
::
findMulti
(
struct
Stream
::
MultiTarget
*
targets
,
int
tCount
)
{
// any zero length target string automatically matches and would make
// a mess of the rest of the algorithm.
for
(
struct
MultiTarget
*
t
=
targets
;
t
<
targets
+
tCount
;
++
t
)
for
(
struct
MultiTarget
*
t
=
targets
;
t
<
targets
+
tCount
;
++
t
)
{
if
(
t
->
len
<=
0
)
return
t
-
targets
;
}
while
(
1
)
{
while
(
1
)
{
int
c
=
timedRead
();
if
(
c
<
0
)
return
-
1
;
for
(
struct
MultiTarget
*
t
=
targets
;
t
<
targets
+
tCount
;
++
t
)
{
// the simple case is if we match, deal with that first.
if
(
c
==
t
->
str
[
t
->
index
])
if
(
++
t
->
index
==
t
->
len
)
return
t
-
targets
;
else
continue
;
if
(
c
==
t
->
str
[
t
->
index
])
{
if
(
++
t
->
index
==
t
->
len
)
return
t
-
targets
;
else
continue
;
}
// if not we need to walk back and see if we could have matched further
// down the stream (ie '1112' doesn't match the first position in '11112'
// but it will match the second position so we can't just reset the current
// index to 0 when we find a mismatch.
if
(
t
->
index
==
0
)
continue
;
continue
;
int
origIndex
=
t
->
index
;
do
{
--
t
->
index
;
// first check if current char works against the new current index
if
(
c
!=
t
->
str
[
t
->
index
])
continue
;
// if it's the only char then we're good, nothing more to check
if
(
t
->
index
==
0
)
{
t
->
index
++
;
break
;
}
// otherwise we need to check the rest of the found string
int
diff
=
origIndex
-
t
->
index
;
int
i
;
for
(
i
=
0
;
i
<
t
->
index
;
++
i
)
if
(
t
->
str
[
i
]
!=
t
->
str
[
i
+
diff
])
break
;
// if we successfully got through the previous loop then our current
// index is good.
if
(
i
==
t
->
index
)
{
t
->
index
++
;
break
;
}
// otherwise we just try the next index
--
t
->
index
;
// first check if current char works against the new current index
if
(
c
!=
t
->
str
[
t
->
index
])
continue
;
// if it's the only char then we're good, nothing more to check
if
(
t
->
index
==
0
)
{
t
->
index
++
;
break
;
}
// otherwise we need to check the rest of the found string
int
diff
=
origIndex
-
t
->
index
;
size_t
i
;
for
(
i
=
0
;
i
<
t
->
index
;
++
i
)
{
if
(
t
->
str
[
i
]
!=
t
->
str
[
i
+
diff
])
break
;
}
// if we successfully got through the previous loop then our current
// index is good.
if
(
i
==
t
->
index
)
{
t
->
index
++
;
break
;
}
// otherwise we just try the next index
}
while
(
t
->
index
);
}
}
// unreachable
return
-
1
;
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment