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.
Fork of WIZnetInterface by
Socket/pico_string.h@38:67e763cdde02, 2017-10-12 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Thu Oct 12 12:19:11 2017 +0200
- Revision:
- 38:67e763cdde02
- Parent:
- 32:f6d76a55a50b
Enable Interrupts for all sockets by default.
Added a Soft-Reset in the reset() functions which works perfect
when no Reset line is connected.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Soohwan Kim |
0:6f28332c466f | 1 | // pico_string.h 2013/8/27 |
| Soohwan Kim |
0:6f28332c466f | 2 | #pragma once |
| Soohwan Kim |
0:6f28332c466f | 3 | class pico_string { |
| Soohwan Kim |
0:6f28332c466f | 4 | public: |
| Soohwan Kim |
0:6f28332c466f | 5 | pico_string(){ |
| Soohwan Kim |
0:6f28332c466f | 6 | _len = 0; |
| Soohwan Kim |
0:6f28332c466f | 7 | _buf = (char*)malloc(1); |
| Soohwan Kim |
0:6f28332c466f | 8 | if (_buf) { |
| Soohwan Kim |
0:6f28332c466f | 9 | _buf[0] = '\0'; |
| Soohwan Kim |
0:6f28332c466f | 10 | } |
| Soohwan Kim |
0:6f28332c466f | 11 | } |
| Soohwan Kim |
0:6f28332c466f | 12 | ~pico_string() { |
| Soohwan Kim |
0:6f28332c466f | 13 | if (_buf) { |
| Soohwan Kim |
0:6f28332c466f | 14 | free(_buf); |
| Soohwan Kim |
0:6f28332c466f | 15 | } |
| Soohwan Kim |
0:6f28332c466f | 16 | } |
| Soohwan Kim |
0:6f28332c466f | 17 | bool empty() { |
| Soohwan Kim |
0:6f28332c466f | 18 | return _len == 0; |
| Soohwan Kim |
0:6f28332c466f | 19 | } |
| Soohwan Kim |
0:6f28332c466f | 20 | void append(const char* s, int len) { |
| Soohwan Kim |
0:6f28332c466f | 21 | if (_buf == NULL) { |
| Soohwan Kim |
0:6f28332c466f | 22 | return; |
| Soohwan Kim |
0:6f28332c466f | 23 | } |
| Soohwan Kim |
0:6f28332c466f | 24 | char* p = (char*)malloc(_len+len+1); |
| Soohwan Kim |
0:6f28332c466f | 25 | if (p == NULL) { |
| Soohwan Kim |
0:6f28332c466f | 26 | return; |
| Soohwan Kim |
0:6f28332c466f | 27 | } |
| Soohwan Kim |
0:6f28332c466f | 28 | memcpy(p, _buf, _len); |
| Soohwan Kim |
0:6f28332c466f | 29 | memcpy(p+_len, s, len); |
| Soohwan Kim |
0:6f28332c466f | 30 | p[_len+len] = '\0'; |
| Soohwan Kim |
0:6f28332c466f | 31 | free(_buf); |
| Soohwan Kim |
0:6f28332c466f | 32 | _buf = p; |
| Soohwan Kim |
0:6f28332c466f | 33 | } |
| Soohwan Kim |
0:6f28332c466f | 34 | void append(const char* s) { |
| Soohwan Kim |
0:6f28332c466f | 35 | append(s, strlen(s)); |
| Soohwan Kim |
0:6f28332c466f | 36 | } |
| Soohwan Kim |
0:6f28332c466f | 37 | char* c_str() { |
| Soohwan Kim |
0:6f28332c466f | 38 | if (_buf) { |
| Soohwan Kim |
0:6f28332c466f | 39 | return _buf; |
| Soohwan Kim |
0:6f28332c466f | 40 | } |
| Helmut Tschemernjak | 32:f6d76a55a50b | 41 | return (char *)""; |
| Soohwan Kim |
0:6f28332c466f | 42 | } |
| Soohwan Kim |
0:6f28332c466f | 43 | private: |
| Soohwan Kim |
0:6f28332c466f | 44 | char* _buf; |
| Soohwan Kim |
0:6f28332c466f | 45 | int _len; |
| Soohwan Kim |
0:6f28332c466f | 46 | }; |
