Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: getline.cpp
- Revision:
- 0:ec7de5c0199f
diff -r 000000000000 -r ec7de5c0199f getline.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/getline.cpp Wed Feb 10 15:34:58 2010 +0000
@@ -0,0 +1,32 @@
+#include "mbed.h"
+// receive a line from a stream, allowing backspace editing,
+// and checking for buffer overflow. Terminates on either a \n or \r.
+size_t getline(Stream &s, char *buf, size_t bufsize)
+{
+ char c;
+ size_t receivedChars = 0;
+ for(;;)
+ {
+ c = s.getc();
+ if (c == '\r' || c == '\n')
+ break;
+ s.putc(c);
+ if (c == '\b')
+ {
+ if (receivedChars > 0)
+ {
+ buf--;
+ receivedChars--;
+ }
+ }
+ else if (receivedChars < bufsize - 1)
+ {
+ *buf++ = c;
+ receivedChars++;
+ }
+ }
+ *buf++ = 0;
+ s.putc('\n');
+ s.putc('\r');
+ return receivedChars;
+}
\ No newline at end of file