From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/string%2Fbyte%2Fstrxfrm.html | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 devdocs/c/string%2Fbyte%2Fstrxfrm.html (limited to 'devdocs/c/string%2Fbyte%2Fstrxfrm.html') diff --git a/devdocs/c/string%2Fbyte%2Fstrxfrm.html b/devdocs/c/string%2Fbyte%2Fstrxfrm.html new file mode 100644 index 00000000..15aa44a8 --- /dev/null +++ b/devdocs/c/string%2Fbyte%2Fstrxfrm.html @@ -0,0 +1,65 @@ +

strxfrm

Defined in header <string.h>
size_t strxfrm( char          *dest, const char          *src, size_t count );
+
(until C99)
size_t strxfrm( char *restrict dest, const char *restrict src, size_t count );
+
(since C99)

Transforms the null-terminated byte string pointed to by src into the implementation-defined form such that comparing two transformed strings with strcmp gives the same result as comparing the original strings with strcoll, in the current C locale.

+

The first count characters of the transformed string are written to destination, including the terminating null character, and the length of the full transformed string is returned, excluding the terminating null character.

+

The behavior is undefined if the dest array is not large enough. The behavior is undefined if dest and src overlap.

+

If count is ​0​, then dest is allowed to be a null pointer.

+

Notes

The correct length of the buffer that can receive the entire transformed string is 1+strxfrm(NULL, src, 0)

+

This function is used when making multiple locale-dependent comparisons using the same string or set of strings, because it is more efficient to use strxfrm to transform all the strings just once, and subsequently compare the transformed strings with strcmp.

+

Parameters

+ + + +
dest - pointer to the first element of the array where the transformed string will be written
src - pointer to the first character of a null-terminated byte string to transform
count - maximum number of characters to be written

Return value

The length of the transformed string, not including the terminating null-character.

+

Example

#include <stdio.h>
+#include <string.h>
+#include <locale.h>
+ 
+int main(void)
+{
+    setlocale(LC_COLLATE, "cs_CZ.iso88592");
+ 
+    const char *in1 = "hrnec";
+    char out1[1+strxfrm(NULL, in1, 0)];
+    strxfrm(out1, in1, sizeof out1);
+ 
+    const char *in2 = "chrt";
+    char out2[1+strxfrm(NULL, in2, 0)];
+    strxfrm(out2, in2, sizeof out2);
+ 
+    printf("In the Czech locale: ");
+    if(strcmp(out1, out2) < 0)
+         printf("%s before %s\n",in1, in2);
+    else
+         printf("%s before %s\n",in2, in1);
+ 
+    printf("In lexicographical comparison: ");
+    if(strcmp(in1, in2)<0)
+         printf("%s before %s\n",in1, in2);
+    else
+         printf("%s before %s\n",in2, in1);
+ 
+}

Possible output:

+
In the Czech locale: hrnec before chrt
+In lexicographical comparison: chrt before hrnec

References

See also

+ + + + +
compares two strings in accordance to the current locale
(function)
+
(C95)
compares two wide strings in accordance to the current locale
(function)
compares two strings
(function)
+
(C95)
transform a wide string so that wcscmp would produce the same result as wcscoll
(function)
C++ documentation for strxfrm
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/string/byte/strxfrm +

+
-- cgit v1.2.3