Skip to content

Allow users to change line endings in the print function #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ size_t Print::print(const Printable& x)

size_t Print::println(void)
{
return write("\r\n");
return write(line_ending);
}

size_t Print::println(const String &s)
Expand Down Expand Up @@ -198,6 +198,10 @@ size_t Print::println(const Printable& x)
return n;
}

void Print::set_line_ending(const char * ending){
line_ending = ending;
}

// Private Methods /////////////////////////////////////////////////////////////

size_t Print::printNumber(unsigned long n, uint8_t base)
Expand Down
9 changes: 7 additions & 2 deletions cores/arduino/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ class Print
int write_error;
size_t printNumber(unsigned long, uint8_t);
size_t printFloat(double, uint8_t);
const char * line_ending;
protected:
void setWriteError(int err = 1) { write_error = err; }
public:
Print() : write_error(0) {}

Print() : write_error(0) {
line_ending = "\r\n";
}

int getWriteError() { return write_error; }
void clearWriteError() { setWriteError(0); }

Expand Down Expand Up @@ -87,6 +90,8 @@ class Print
size_t println(const Printable&);
size_t println(void);

void set_line_ending(const char * ending);

virtual void flush() { /* Empty implementation for backward compatibility */ }
};

Expand Down