| 279 | /////////////////////////////////////////////////////////////////////////////// |
| 280 | |
| 281 | void DumpTextToClipboard(char *text) { |
| 282 | char *ptr; |
| 283 | |
| 284 | // Count number of carriage returns to be added |
| 285 | char last_char = 0; |
| 286 | int extra = 0; |
| 287 | ptr = text; |
| 288 | while (*ptr) { |
| 289 | if ((*ptr == '\n') && (last_char != '\r')) { |
| 290 | extra++; |
| 291 | } |
| 292 | last_char = *ptr++; |
| 293 | } |
| 294 | |
| 295 | // Length of string with CRs added |
| 296 | size_t len = strlen(text) + extra + 1; |
| 297 | |
| 298 | HGLOBAL h_text = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, len); |
| 299 | if (!h_text) |
| 300 | return; |
| 301 | ptr = (char *)GlobalLock(h_text); |
| 302 | if (!ptr) |
| 303 | return; |
| 304 | |
| 305 | // copy then, if you find any \n's without \r's, then add in the \r. |
| 306 | last_char = 0; |
| 307 | while (*text) { |
| 308 | if ((*text == '\n') && (last_char != '\r')) { |
| 309 | *ptr++ = '\r'; |
| 310 | } |
| 311 | last_char = *text; |
| 312 | *ptr++ = last_char; |
| 313 | text++; |
| 314 | } |
| 315 | *ptr = 0; // terminate string |
| 316 | GlobalUnlock(h_text); |
| 317 | OpenClipboard(NULL); |
| 318 | EmptyClipboard(); |
| 319 | SetClipboardData(CF_TEXT, h_text); |
| 320 | CloseClipboard(); |
| 321 | } |
| 322 | |
| 323 | void dump_text_to_clipboard(char *text) { DumpTextToClipboard(text); } |
| 324 |
no outgoing calls
no test coverage detected