summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-26 16:44:10 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-26 16:44:10 +0900
commitb3d40d393e45d97619ef4b750b5295b2f3fdbd98 (patch)
treef947e841d196f8eb0d3c1e6e9835a544ffb777f0
parent1b8643b9a00812f3362eafbf53ac5d70e6a0601e (diff)
elm cnp win32 - do one side at least of unix newlines to windows newln
this PARTLY addresses T3556 ... this handles our own conversion of makrup to string then to a windows newlined string. this half. i wrote the conversion code for the other way but it's unused as i am unsure where exactly to plug in it. following the cnp code makes me not sure where it goes so for now - not there, but ready to go. to be clear. out API is unix text. utf8 strings at our api with UNIX newlines. that is our api. that is the text we accept and produce. if you deal with another file or interface that does not provide this then the job of conversion is AT THAT POINT. eg elm_cnp.c has to do this. as would file loads of text files (and saves) etc. - anything else like forgivingly handling anything at the api level makes it totally unclear what our api is and what should go in and come out. to be portable we have to define what it is and the most portable thing to do is at the api level within a process we define one and only one format. UNIX \n format. @fix - partial
-rw-r--r--src/lib/elementary/elm_cnp.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/lib/elementary/elm_cnp.c b/src/lib/elementary/elm_cnp.c
index f9fdd14..bab1076 100644
--- a/src/lib/elementary/elm_cnp.c
+++ b/src/lib/elementary/elm_cnp.c
@@ -4526,6 +4526,56 @@ static Win32_Cnp_Selection _win32_selections[ELM_SEL_TYPE_CLIPBOARD + 1] =
4526 } 4526 }
4527}; 4527};
4528 4528
4529static char *
4530_win32_text_n_to_rn(char *intext)
4531{
4532 size_t size = 0, newlines = 0;
4533 char *outtext = NULL, *p, *o;
4534
4535 if (!intext) return NULL;
4536 for (p = intext; *p; p++)
4537 {
4538 if (*p == '\n') newlines++;
4539 size++;
4540 }
4541 outtext = malloc(size + newlines + 1);
4542 if (!outtext) return intext;
4543 for (p = intext, o = outtext; *p; p++, o++)
4544 {
4545 if (*p == '\n')
4546 {
4547 o++;
4548 *p = '\r';
4549 }
4550 *o = *p;
4551 }
4552 *o = '\0';
4553 free(intext);
4554 return outtext;
4555}
4556
4557static char *
4558_win32_text_rn_to_n(char *intext)
4559{
4560 size_t size = 0, newlines = 0;
4561 char *outtext = NULL, *p, *o;
4562
4563 if (!intext) return NULL;
4564 outtext = malloc(strlen(intext) + 1);
4565 if (!outtext) return intext;
4566 for (p = intext, o = outtext; *p; p++, o++)
4567 {
4568 if ((*p == '\r') && (p[1] == '\n'))
4569 {
4570 p++;
4571 *p = '\n';
4572 }
4573 else *o = *p;
4574 }
4575 *o = '\0';
4576 free(intext);
4577 return outtext;
4578}
4529 4579
4530static void 4580static void
4531_win32_sel_obj_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) 4581_win32_sel_obj_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
@@ -4741,7 +4791,7 @@ _win32_elm_cnp_selection_get(Ecore_Win32_Window *win,
4741 { 4791 {
4742 memcpy(str, data, size); 4792 memcpy(str, data, size);
4743 str[size] = '\0'; 4793 str[size] = '\0';
4744 data = _elm_util_mkup_to_text(str); 4794 data = _win32_text_n_to_rn(_elm_util_mkup_to_text(str));
4745 free(str); 4795 free(str);
4746 if (data) 4796 if (data)
4747 size = strlen(data); 4797 size = strlen(data);