Mercurial > pidgin.yaz
comparison libpurple/util.c @ 27826:5f9ca519ea9f
propagate from branch 'im.pidgin.pidgin' (head 90011f8844f95be26206d5698b603f1692f319a0)
to branch 'im.pidgin.pidgin.yaz' (head e4862d866bc0b147e783d27c1faa51f1d3e0b58a)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 24 Apr 2008 02:28:24 +0000 |
parents | 85d5b6c06a6c |
children | f9fd7ddf6996 |
comparison
equal
deleted
inserted
replaced
22698:80c87908ff1d | 27826:5f9ca519ea9f |
---|---|
1207 | 1207 |
1208 if (check_value != '\0' && *p == check_value) | 1208 if (check_value != '\0' && *p == check_value) |
1209 return FALSE; | 1209 return FALSE; |
1210 | 1210 |
1211 q = strstr(p, end_token); | 1211 q = strstr(p, end_token); |
1212 if(q == NULL) //yaz | |
1213 return FALSE; | |
1212 | 1214 |
1213 /* Trim leading blanks */ | 1215 /* Trim leading blanks */ |
1214 while (*p != '\n' && g_ascii_isspace(*p)) { | 1216 while (*p != '\n' && g_ascii_isspace(*p)) { |
1215 p += 1; | 1217 p += 1; |
1216 } | 1218 } |
1219 while (q > p && g_ascii_isspace(*(q - 1))) { | 1221 while (q > p && g_ascii_isspace(*(q - 1))) { |
1220 q -= 1; | 1222 q -= 1; |
1221 } | 1223 } |
1222 | 1224 |
1223 /* Don't bother with null strings */ | 1225 /* Don't bother with null strings */ |
1224 if (p == q) | 1226 if (p >= q) |
1225 return FALSE; | 1227 return FALSE; |
1226 | 1228 |
1227 if (q != NULL && (!no_value_token || | 1229 if (q != NULL && (!no_value_token || |
1228 (no_value_token && strncmp(p, no_value_token, | 1230 (no_value_token && strncmp(p, no_value_token, |
1229 strlen(no_value_token))))) | 1231 strlen(no_value_token))))) |
4705 } | 4707 } |
4706 | 4708 |
4707 return g_string_free(string, FALSE); | 4709 return g_string_free(string, FALSE); |
4708 } | 4710 } |
4709 | 4711 |
4712 | |
4713 #ifdef _WIN32 | |
4714 void botch_ucs(gchar *ucs_src, gsize len) | |
4715 { | |
4716 /* no operation */ | |
4717 } | |
4718 #else | |
4719 void botch_ucs(gchar *ucs_src, gsize len) | |
4720 { | |
4721 gint i; | |
4722 guchar *ucs = (guchar *)ucs_src; | |
4723 | |
4724 g_return_if_fail(ucs_src != NULL); | |
4725 g_return_if_fail(len > 0); | |
4726 | |
4727 for(i=0;i<len;i+=2){ | |
4728 switch(*(ucs+i)){ | |
4729 case 0x00: | |
4730 switch(*(ucs+i+1)){ | |
4731 case 0xa2: // ¢ | |
4732 *(ucs+i) = 0xff; | |
4733 *(ucs+i+1) = 0xe0; | |
4734 break; | |
4735 case 0xa3: // £ | |
4736 *(ucs+i) = 0xff; | |
4737 *(ucs+i+1) = 0xe1; | |
4738 break; | |
4739 case 0xac: // ¬ | |
4740 *(ucs+i) = 0xff; | |
4741 *(ucs+i+1) = 0xe2; | |
4742 break; | |
4743 } | |
4744 break; | |
4745 case 0x20: // ‖ | |
4746 if(*(ucs+i+1) == 0x16){ | |
4747 *(ucs+i) = 0x22; | |
4748 *(ucs+i+1) = 0x25; | |
4749 } | |
4750 break; | |
4751 case 0x22: // − | |
4752 if(*(ucs+i+1) == 0x12){ | |
4753 *(ucs+i) = 0xff; | |
4754 *(ucs+i+1) = 0x0d; | |
4755 } | |
4756 break; | |
4757 case 0x30: // 〜 | |
4758 if(*(ucs+i+1) == 0x1c){ | |
4759 *(ucs+i) = 0xff; | |
4760 *(ucs+i+1) = 0x5e; | |
4761 } | |
4762 break; | |
4763 } | |
4764 } | |
4765 | |
4766 } | |
4767 #endif | |
4768 | |
4769 #ifdef _WIN32 | |
4770 void sanitize_ucs(gchar *ucs, gsize len) | |
4771 { | |
4772 /* no operation */ | |
4773 } | |
4774 #else | |
4775 void sanitize_ucs(gchar *ucs_src, gsize len) | |
4776 { | |
4777 gint i; | |
4778 guchar *ucs = (guchar *)ucs_src; | |
4779 | |
4780 g_return_if_fail(ucs_src != NULL); | |
4781 g_return_if_fail(len > 0); | |
4782 | |
4783 for(i=0;i<len;i+=2){ | |
4784 switch(*(ucs+i)){ | |
4785 case 0x22: | |
4786 switch(*(ucs+i+1)){ | |
4787 case 0x25: // ‖ | |
4788 *(ucs+i) = 0x20; | |
4789 *(ucs+i+1) = 0x16; | |
4790 break; | |
4791 } | |
4792 break; | |
4793 case 0xff: | |
4794 switch(*(ucs+i+1)){ | |
4795 case 0x0d: // − | |
4796 *(ucs+i) = 0x22; | |
4797 *(ucs+i+1) = 0x12; | |
4798 break; | |
4799 case 0x5e: // 〜 | |
4800 *(ucs+i) = 0x30; | |
4801 *(ucs+i+1) = 0x1c; | |
4802 break; | |
4803 case 0xe0: // ¢ | |
4804 *(ucs+i) = 0x00; | |
4805 *(ucs+i+1) = 0xa2; | |
4806 break; | |
4807 case 0xe1: // £ | |
4808 *(ucs+i) = 0x00; | |
4809 *(ucs+i+1) = 0xa3; | |
4810 break; | |
4811 case 0xe2: // ¬ | |
4812 *(ucs+i) = 0x00; | |
4813 *(ucs+i+1) = 0xac; | |
4814 break; | |
4815 } | |
4816 break; | |
4817 } | |
4818 } | |
4819 } | |
4820 #endif | |
4821 | |
4822 #ifdef _WIN32 | |
4823 gchar *sanitize_utf(const gchar *msg, gsize len, gsize *newlen) | |
4824 { | |
4825 g_return_val_if_fail(msg != NULL, NULL); | |
4826 if(len == -1) | |
4827 len = strlen(msg); | |
4828 g_return_val_if_fail(len > 0, NULL); | |
4829 | |
4830 if(newlen) | |
4831 *newlen = len; | |
4832 | |
4833 return g_strndup(msg, len); | |
4834 } | |
4835 #else | |
4836 gchar *sanitize_utf(const gchar *msg, gsize len, gsize *newlen) | |
4837 { | |
4838 gint i; | |
4839 size_t bytes; | |
4840 guchar *utf; | |
4841 | |
4842 g_return_val_if_fail(msg != NULL, NULL); | |
4843 if(len == -1) | |
4844 len = strlen(msg); | |
4845 g_return_val_if_fail(len > 0, NULL); | |
4846 | |
4847 utf = (guchar *)g_strndup(msg, len); | |
4848 | |
4849 bytes = len; | |
4850 | |
4851 for(i=0;i<len;i++){ | |
4852 switch(*(utf+i)){ | |
4853 case 0xe2: | |
4854 if(*(utf+i+1) == 0x88) { | |
4855 if(*(utf+i+2) == 0xa5) { // ‖ | |
4856 *(utf+i) = 0xe2; | |
4857 *(utf+i+1) = 0x80; | |
4858 *(utf+i+2) = 0x96; | |
4859 } | |
4860 } | |
4861 break; | |
4862 case 0xef: | |
4863 switch(*(utf+i+1)){ | |
4864 case 0xbc: | |
4865 if(*(utf+i+2) == 0x8d) { // − | |
4866 *(utf+i) = 0xe2; | |
4867 *(utf+i+1) = 0x88; | |
4868 *(utf+i+2) = 0x92; | |
4869 } | |
4870 break; | |
4871 case 0xbd: | |
4872 if(*(utf+i+2) == 0x9e) { // 〜 | |
4873 *(utf+i) = 0xe3; | |
4874 *(utf+i+1) = 0x80; | |
4875 *(utf+i+2) = 0x9c; | |
4876 } | |
4877 break; | |
4878 case 0xbf: | |
4879 switch(*(utf+i+2)){ | |
4880 case 0xa0: // ¢ | |
4881 *(utf+i) = 0xc2; | |
4882 *(utf+i+1) = 0xa2; | |
4883 memmove(utf+i+2, utf+i+3, | |
4884 len-i-3); //shorten by 1byte | |
4885 bytes--; | |
4886 break; | |
4887 case 0xa1: // £ | |
4888 *(utf+i) = 0xc2; | |
4889 *(utf+i+1) = 0xa3; | |
4890 memmove(utf+i+2, utf+i+3, | |
4891 len-i-3); //shorten by 1byte | |
4892 bytes--; | |
4893 break; | |
4894 case 0xa2: // ¬ | |
4895 *(utf+i) = 0xc2; | |
4896 *(utf+i+1) = 0xac; | |
4897 memmove(utf+i+2, utf+i+3, | |
4898 len-i-3); //shorten by 1byte | |
4899 bytes--; | |
4900 break; | |
4901 } | |
4902 break; | |
4903 } | |
4904 break; | |
4905 } | |
4906 } | |
4907 *(utf+bytes)= 0x00; //terminate | |
4908 if(newlen) | |
4909 *newlen = bytes; | |
4910 return (gchar *)utf; | |
4911 } | |
4912 #endif | |
4913 | |
4914 #ifdef _WIN32 | |
4915 gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) | |
4916 { | |
4917 g_return_val_if_fail(msg != NULL, NULL); | |
4918 if(len == -1) | |
4919 len = strlen(msg); | |
4920 g_return_val_if_fail(len > 0, NULL); | |
4921 | |
4922 if(newlen) | |
4923 *newlen = len; | |
4924 | |
4925 return g_strndup(msg, len); | |
4926 } | |
4927 #else | |
4928 gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) | |
4929 { | |
4930 int i,bytes; | |
4931 unsigned char *utf; | |
4932 | |
4933 g_return_val_if_fail(msg != NULL, NULL); | |
4934 if(len == -1) | |
4935 len = strlen(msg); | |
4936 g_return_val_if_fail(len > 0, NULL); | |
4937 | |
4938 bytes = len; | |
4939 | |
4940 utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */ | |
4941 memcpy(utf, msg, bytes); | |
4942 | |
4943 for(i=0;i<bytes;i++){ | |
4944 switch(*(utf+i)){ | |
4945 case 0xc2: | |
4946 switch(*(utf+i+1)){ | |
4947 case 0xa2: // ¢ | |
4948 *(utf+i) = 0xef; | |
4949 *(utf+i+1) = 0xbf; | |
4950 memmove(utf+i+3, utf+i+2, bytes-i-2); | |
4951 *(utf+i+2) = 0xa0; | |
4952 bytes++; | |
4953 break; | |
4954 case 0xa3: // £ | |
4955 *(utf+i) = 0xef; | |
4956 *(utf+i+1) = 0xbf; | |
4957 memmove(utf+i+3, utf+i+2, bytes-i-2); | |
4958 *(utf+i+2) = 0xa1; | |
4959 bytes++; | |
4960 break; | |
4961 case 0xac: // ¬ | |
4962 *(utf+i) = 0xef; | |
4963 *(utf+i+1) = 0xbf; | |
4964 memmove(utf+i+3, utf+i+2, bytes-i-2); | |
4965 *(utf+i+2) = 0xa2; | |
4966 bytes++; | |
4967 break; | |
4968 } | |
4969 break; | |
4970 case 0xe2: | |
4971 switch(*(utf+i+1)){ | |
4972 case 0x80: // ‖ | |
4973 if(*(utf+i+2) == 0x96){ | |
4974 *(utf+i) = 0xe2; | |
4975 *(utf+i+1) = 0x88; | |
4976 *(utf+i+2) = 0xa5; | |
4977 } | |
4978 break; | |
4979 case 0x88: // − | |
4980 if(*(utf+i+1) == 0x92){ | |
4981 *(utf+i) = 0xef; | |
4982 *(utf+i+1) = 0xbc; | |
4983 *(utf+i+2) = 0x8d; | |
4984 } | |
4985 break; | |
4986 } | |
4987 break; | |
4988 case 0xe3: // 〜 | |
4989 if(*(utf+i+1) == 0x80){ | |
4990 if(*(utf+i+2) == 0x9c){ | |
4991 *(utf+i) = 0xef; | |
4992 *(utf+i+1) = 0xbd; | |
4993 *(utf+i+2) = 0x9e; | |
4994 } | |
4995 } | |
4996 break; | |
4997 } //switch | |
4998 } | |
4999 *(utf+bytes) = 0x00; //terminate | |
5000 if(newlen) | |
5001 *newlen = bytes; | |
5002 return (gchar *)utf; | |
5003 } | |
5004 #endif |