|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * FUNCTION |
|
16 * <<strxfrm>>---transform string |
|
17 * INDEX |
|
18 * strxfrm |
|
19 * ANSI_SYNOPSIS |
|
20 * #include <string.h> |
|
21 * size_t strxfrm(char *<[s1]>, const char *<[s2]>, size_t <[n]>); |
|
22 * TRAD_SYNOPSIS |
|
23 * #include <string.h> |
|
24 * size_t strxfrm(<[s1]>, <[s2]>, <[n]>); |
|
25 * char *<[s1]>; |
|
26 * char *<[s2]>; |
|
27 * size_t <[n]>; |
|
28 * This function transforms the string pointed to by <[s2]> and |
|
29 * places the resulting string into the array pointed to by |
|
30 * <[s1]>. The transformation is such that if the <<strcmp>> |
|
31 * function is applied to the two transformed strings, it returns |
|
32 * a value greater than, equal to, or less than zero, |
|
33 * correspoinding to the result of a <<strcoll>> function applied |
|
34 * to the same two original strings. |
|
35 * No more than <[n]> characters are placed into the resulting |
|
36 * array pointed to by <[s1]>, including the terminating null |
|
37 * character. If <[n]> is zero, <[s1]> may be a null pointer. If |
|
38 * copying takes place between objects that overlap, the behavior |
|
39 * is undefined. |
|
40 * With a C locale, this function just copies. |
|
41 * RETURNS |
|
42 * The <<strxfrm>> function returns the length of the transformed string |
|
43 * (not including the terminating null character). If the value returned |
|
44 * is <[n]> or more, the contents of the array pointed to by |
|
45 * <[s1]> are indeterminate. |
|
46 * PORTABILITY |
|
47 * <<strxfrm>> is ANSI C. |
|
48 * <<strxfrm>> requires no supporting OS subroutines. |
|
49 * QUICKREF |
|
50 * strxfrm ansi pure |
|
51 * |
|
52 * |
|
53 */ |
|
54 |
|
55 |
|
56 |
|
57 #include <string.h> |
|
58 |
|
59 /** |
|
60 Transform string using locale settings. |
|
61 Copies the first num characters of src to dest performing the apropiate |
|
62 transformations for the current locale settings if needed. |
|
63 No null-character is implicitly appended to dest after copying process. |
|
64 So dest may not be null-terminated if no null-caracters are copied from src. |
|
65 If num is greater than the length of src, dest is padded with zeros until num. |
|
66 The behavor of this function is the same as strncpy but performing locale |
|
67 character transformations. |
|
68 @return The length of the transformed string without the null-character terminator. |
|
69 @param s1 Destination string. Space allocated should be at least num characters long. |
|
70 @param s2 Null-terminated string containing string to be transformed. |
|
71 @param n Number of characters to be transformed and stored in dest. |
|
72 */ |
|
73 EXPORT_C size_t |
|
74 strxfrm (char *s1, const char *s2, size_t n) |
|
75 { |
|
76 size_t res; |
|
77 res = 0; |
|
78 while (n-- > 0 && *s2) |
|
79 { |
|
80 *s1++ = *s2++; |
|
81 res++; |
|
82 } |
|
83 while (*s2) |
|
84 { |
|
85 s2++; |
|
86 res++; |
|
87 } |
|
88 |
|
89 return res; |
|
90 } |