Skip to content

uBit.serial.readUntil() with multiple chars (like \r\n) returns as soon as any of the chars is found #303

Open
@microbit-carlos

Description

@microbit-carlos

From the docs:
https://github.com/lancaster-university/codal-core/blob/350a794a6f43d8e91b4762f110bad675169dc908/source/driver-models/Serial.cpp#L687

 * Reads until one of the delimeters matches a character in the rxBuff
 *
 * @param delimeters a ManagedString containing a sequence of delimeter characters e.g. ManagedString("\r\n")
...
 * @return A ManagedString containing the characters up to a delimeter, or ...

From that I would understand that if we send the string "hello\r\nworld\r\n" then uBit.serial.readUntil("\r\n") would return first "hello" and then "world".

However, it returns up to the first match from any of the delimeters, so as it matches \r OR \n, we end up getting four strings: "hello", "" (empty), "world", "" (empty).

The last note from that docstring indicates:

 * @note delimeters are matched on a per byte basis.

Does that mean the current behaviour is the done by design? Doesn't feel as useful for the most common case of trying to match \r\n?

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions