Skip to content

Migrate Stream search internals from char to uint8_t#274

Open
asumo-1xts wants to merge 3 commits into
arduino:masterfrom
asumo-1xts:issue#119
Open

Migrate Stream search internals from char to uint8_t#274
asumo-1xts wants to merge 3 commits into
arduino:masterfrom
asumo-1xts:issue#119

Conversation

@asumo-1xts

@asumo-1xts asumo-1xts commented Jun 7, 2026

Copy link
Copy Markdown

Overview

This PR is regarding issue #119.

With the current code, Stream::find() cannot find values above 0x7f because it treats the target string as char, meaning that many UTF-8 encoded characters cannot be matched either.
This PR fixes the issue by changing the target string type from char to uint8_t.

Verification on an actual device

Find single-byte number above 0x7f

When 0x80 is sent via the serial monitor, the sketch below returns "Not found.” with current code while it returns “Found!” this PR's fixed code.

#include <Arduino.h>

const uint8_t TARGET_NUM = 0x80; // above 0x7f

void setup() { Serial.begin(115200); }

void loop() {
  if (Serial.available()) {
    if (Serial.find(TARGET_NUM)) {
      Serial.println("Found!");
    } else {
      Serial.println("Not found.");
    }
  }
}

Find multi-byte UTF-8 character

With the current code, the sketch below fails to build with the error no instance of overloaded function "Serial_::find" matches the argument list. With the fixed code, it builds and works as expected.

#include <Arduino.h>

const uint8_t TARGET_STR[] = "やあ😀";
// E3 82 84 + E3 81 82 + F0 9F 98 80

void setup() { Serial.begin(115200); }

void loop() {
  if (Serial.available()) {
    if (Serial.find(TARGET_STR)) {
      Serial.println("Found!");
    } else {
      Serial.println("Not found.");
    }
  }
}

@CLAassistant

CLAassistant commented Jun 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 linked an issue Jun 8, 2026 that may be closed by this pull request
@asumo-1xts

Copy link
Copy Markdown
Author

I just realized that this PR might also fix these issues:
arduino/ArduinoCore-avr#249
arduino/ArduinoCore-avr#541

@asumo-1xts

Copy link
Copy Markdown
Author

Sorry if my repeated notifications have been noisy.
I have revised my original comment and have nothing further to add at this point.
If there is anything else I should address, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream::find() not working for values above 0x7F

2 participants