os/ossrv/genericopenlibs/cstdlib/LCHAR/STRXFRM.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRXFRM.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,90 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +* FUNCTION
    1.19 +* <<strxfrm>>---transform string
    1.20 +* INDEX
    1.21 +* strxfrm
    1.22 +* ANSI_SYNOPSIS
    1.23 +* #include <string.h>
    1.24 +* size_t strxfrm(char *<[s1]>, const char *<[s2]>, size_t <[n]>);
    1.25 +* TRAD_SYNOPSIS
    1.26 +* #include <string.h>
    1.27 +* size_t strxfrm(<[s1]>, <[s2]>, <[n]>);
    1.28 +* char *<[s1]>;
    1.29 +* char *<[s2]>;
    1.30 +* size_t <[n]>;
    1.31 +* This function transforms the string pointed to by <[s2]> and
    1.32 +* places the resulting string into the array pointed to by
    1.33 +* <[s1]>. The transformation is such that if the <<strcmp>>
    1.34 +* function is applied to the two transformed strings, it returns
    1.35 +* a value greater than, equal to, or less than zero,
    1.36 +* correspoinding to the result of a <<strcoll>> function applied
    1.37 +* to the same two original strings.
    1.38 +* No more than <[n]> characters are placed into the resulting
    1.39 +* array pointed to by <[s1]>, including the terminating null
    1.40 +* character. If <[n]> is zero, <[s1]> may be a null pointer. If
    1.41 +* copying takes place between objects that overlap, the behavior
    1.42 +* is undefined.
    1.43 +* With a C locale, this function just copies.
    1.44 +* RETURNS
    1.45 +* The <<strxfrm>> function returns the length of the transformed string
    1.46 +* (not including the terminating null character). If the value returned
    1.47 +* is <[n]> or more, the contents of the array pointed to by
    1.48 +* <[s1]> are indeterminate.
    1.49 +* PORTABILITY
    1.50 +* <<strxfrm>> is ANSI C.
    1.51 +* <<strxfrm>> requires no supporting OS subroutines.
    1.52 +* QUICKREF
    1.53 +* strxfrm ansi pure
    1.54 +* 
    1.55 +*
    1.56 +*/
    1.57 +
    1.58 +
    1.59 +
    1.60 +#include <string.h>
    1.61 +
    1.62 +/**
    1.63 +Transform string using locale settings.
    1.64 +Copies the first num characters of src to dest performing the apropiate
    1.65 +transformations for the current locale settings if needed.
    1.66 +No null-character is implicitly appended to dest after copying process. 
    1.67 +So dest may not be null-terminated if no null-caracters are copied from src.
    1.68 +If num is greater than the length of src, dest is padded with zeros until num.
    1.69 +The behavor of this function is the same as strncpy but performing locale
    1.70 +character transformations.
    1.71 +@return The length of the transformed string without the null-character terminator.
    1.72 +@param s1 Destination string. Space allocated should be at least num characters long. 
    1.73 +@param s2 Null-terminated string containing string to be transformed. 
    1.74 +@param n Number of characters to be transformed and stored in dest.
    1.75 +*/
    1.76 +EXPORT_C size_t
    1.77 +strxfrm (char *s1, const char *s2, size_t n)
    1.78 +{
    1.79 +  size_t res;
    1.80 +  res = 0;
    1.81 +  while (n-- > 0 && *s2)
    1.82 +    {
    1.83 +      *s1++ = *s2++;
    1.84 +      res++;
    1.85 +    }
    1.86 +  while (*s2)
    1.87 +    {
    1.88 +      s2++;
    1.89 +      res++;
    1.90 +    }
    1.91 +
    1.92 +  return res;
    1.93 +}