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