Changeset 104762 in vbox for trunk/src/VBox
- Timestamp:
- May 22, 2024 3:09:51 PM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp
r104761 r104762 910 910 } 911 911 912 int ShClConvUtf16LFToCRLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pu16Dst, size_t cw Dst)912 int ShClConvUtf16LFToCRLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pu16Dst, size_t cwcDst) 913 913 { 914 914 AssertPtrReturn(pcwszSrc, VERR_INVALID_POINTER); 915 915 AssertPtrReturn(pu16Dst, VERR_INVALID_POINTER); 916 AssertReturn(cw Dst, VERR_INVALID_PARAMETER);916 AssertReturn(cwcDst, VERR_INVALID_PARAMETER); 917 917 918 918 AssertMsgReturn(pcwszSrc[0] != VBOX_SHCL_UTF16BEMARKER, 919 919 ("Big endian UTF-16 not supported yet\n"), VERR_NOT_SUPPORTED); 920 920 921 int rc = VINF_SUCCESS;922 923 921 /* Don't copy the endian marker. */ 924 size_t i = pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER ? 1 : 0; 925 size_t j = 0; 926 927 for (; i < cwcSrc; ++i, ++j) 928 { 922 size_t offDst = 0; 923 for (size_t offSrc = pcwszSrc[0] == VBOX_SHCL_UTF16LEMARKER ? 1 : 0; offSrc < cwcSrc; ++offSrc, ++offDst) 924 { 925 /* Ensure more output space: */ 926 if (offDst < cwcDst) { /* likely */ } 927 else return VERR_BUFFER_OVERFLOW; 928 929 929 /* Don't copy the null byte, as we add it below. */ 930 if (pcwszSrc[ i] == 0)930 if (pcwszSrc[offSrc] == 0) 931 931 break; 932 932 933 /* Not enough space in destination? */ 934 if (j == cwDst) 935 { 936 rc = VERR_BUFFER_OVERFLOW; 937 break; 938 } 939 940 if (pcwszSrc[i] == VBOX_SHCL_LINEFEED) 941 { 942 /* Insert '\r' in front of '\n', but avoid '\r\r\n' situations 943 because it will result in extra empty lines on the other side. */ 944 if (i == 0 || pcwszSrc[i - 1] != VBOX_SHCL_CARRIAGERETURN) 945 pu16Dst[j++] = VBOX_SHCL_CARRIAGERETURN; 946 947 /* Not enough space in destination? */ 948 if (j == cwDst) 949 { 950 rc = VERR_BUFFER_OVERFLOW; 951 break; 952 } 933 /* Check for newlines not preceeded by carriage return: "\n" -> "\r\n"; but not "\r\n" to "\r\r\n"! */ 934 if ( pcwszSrc[offSrc] == VBOX_SHCL_LINEFEED 935 && (offSrc == 0 || pcwszSrc[offSrc - 1] != VBOX_SHCL_CARRIAGERETURN)) 936 { 937 pu16Dst[offDst++] = VBOX_SHCL_CARRIAGERETURN; 938 939 /* Ensure sufficient output space: */ 940 if (offDst < cwcDst) { /* likely */ } 941 else return VERR_BUFFER_OVERFLOW; 953 942 } 954 943 #ifdef RT_OS_DARWIN 955 /* Check for a single carriage return (MacOS) */ 956 else if (pcwszSrc[i] == VBOX_SHCL_CARRIAGERETURN) 957 { 958 /* Set CR.r, but avoid '\r\r'. */ 959 if (i == 0 || pcwszSrc[i - 1] != VBOX_SHCL_CARRIAGERETURN) 960 pu16Dst[j++] = VBOX_SHCL_CARRIAGERETURN; 961 962 /* Not enough space in destination? */ 963 if (j == cwDst) 964 { 965 rc = VERR_BUFFER_OVERFLOW; 966 break; 967 } 944 /* Check for a carriage return not followed by newline (MacOS): "\r" -> "\n\r"; but not "\r\n" to "\r\n\n"! */ 945 else if ( pcwszSrc[offSrc] == VBOX_SHCL_CARRIAGERETURN 946 && (offSrc + 1 >= cwcSrc || pcwszSrc[offSrc + 1] != VBOX_SHCL_LINEFEED)) 947 { 948 pu16Dst[offDst++] = VBOX_SHCL_CARRIAGERETURN; 949 950 /* Ensure more output space: */ 951 if (offDst < cwcDst) { /* likely */ } 952 else return VERR_BUFFER_OVERFLOW; 968 953 969 954 /* Add line feed. */ 970 pu16Dst[ j] = VBOX_SHCL_LINEFEED;955 pu16Dst[offDst] = VBOX_SHCL_LINEFEED; 971 956 continue; 972 957 } 973 958 #endif 974 pu16Dst[j] = pcwszSrc[i]; 975 } 976 977 if (j == cwDst) 978 rc = VERR_BUFFER_OVERFLOW; 979 980 if (RT_SUCCESS(rc)) 981 { 982 /* Add terminator. */ 983 pu16Dst[j] = 0; 984 } 985 986 return rc; 959 pu16Dst[offDst] = pcwszSrc[offSrc]; 960 } 961 962 /* Add terminator. */ 963 if (offDst < cwcDst) 964 { 965 pu16Dst[offDst] = 0; 966 return VINF_SUCCESS; 967 } 968 return VERR_BUFFER_OVERFLOW; 987 969 } 988 970
Note:
See TracChangeset
for help on using the changeset viewer.