String Utility

This chapter describes APIs of the utility for string processing.

1. Overview

Strings can be divided into two types: null-terminated strings and fixed-length strings.

  • Null-terminated strings

    • Have a variable length.

    • Ignore characters after a null character ('\0').

    • Example

      {‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘\0’} == “ABCDEFG”
  • Fixed-length strings

    • Have a fixed length.

    • Recognize only as many characters as a given length. However, if a string includes a null character, only characters before the null character are recognized.

    • Example

      [{‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘\0’}, 2] == “AB”
      [{‘A’, ‘B’, ‘C’, ‘\0’, ‘D’, ‘E’}, 6] == “ABC”

2. pfmStrIsLower

Checks whether all characters in a null-terminated string are lowercase.

  • Prototype

    long pfmStrIsLower(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are lowercase.

    FALSE

    The string includes a uppercase character, or its length is 0.

  • Example

    rc = pfmStrIsLower(“     abcDEF  1. 23hljk     ”);
    /* rc == FALSE */
    
    rc = pfmStrIsLower(“     abcdef  1. 23hljk     ”);
    /* rc == TRUE */
    
    rc = pfmStrIsLower(“”);
    /* rc == FALSE */

3. pfmStrnIsLower

Checks whether all characters in a fixed-length string are lowercase.

  • Prototype

    long pfmStrnIsLower(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are lowercase.

    FALSE

    The string includes a uppercase character, or its length is 0.

  • Example

    /* strlen(“abcDEF”) == 6 */
    
    rc = pfmStrnIsLower(“abcDEF”, 1);
    /* rc == TRUE */
    
    rc = pfmStrnIsLower(“abcDEF”, 3);
    /* rc == TRUE */
    
    rc = pfmStrnIsLower(“abcDEF”, 4);
    /* rc == FALSE */
    
    rc = pfmStrnIsLower(“abcDEF”, 6);
    /* rc == FALSE */
    
    rc = pfmStrnIsLower(“abcDEF”, 7);    /* null position */
    /* rc == FALSE */
    
    rc = pfmStrnIsLower(“abcDEF”, 8);    /* after null position */
    /* rc == FALSE */
    
    rc = pfmStrnIsLower(“”, 8);
    /* rc == FALSE */

4. pfmStrIsUpper

Checks whether all characters in a null-terminated string are uppercase.

  • Prototype

    long pfmStrIsUpper(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are uppercase.

    FALSE

    The string includes a lowercase character.

  • Example

    rc = pfmStrIsUpper(“     abcDEF  1. 23hljk     ”);
    /* rc == FALSE */
    
    rc = pfmStrIsUpper(“     abcdef  1. 23hljk     ”);
    /* rc == TRUE */
    
    rc = pfmStrIsUpper(“”);
    /* rc == FALSE */

5. pfmStrnIsUpper

Checks whether all characters in a fixed-length string are uppercase.

  • Prototype

    long pfmStrnIsUpper(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are uppercase.

    FALSE

    The string includes a lowercase character, or its first character is null.

  • Example

    /* strlen(“ABCdef”) == 6 */
    
    rc = pfmStrnIsUpper(“ABCdef”, 1);
    /* rc == TRUE */
    
    rc = pfmStrnIsUpper(“ABCdef”, 3);
    /* rc == TRUE */
    
    rc = pfmStrnIsUpper(“ABCdef”, 4);
    /* rc == FALSE */
    
    rc = pfmStrnIsUpper(“ABCdef”, 6);
    /* rc == FALSE */
    
    rc = pfmStrnIsUpper(“ABCdef”, 7);    /* null position */
    /* rc == FALSE */
    
    rc = pfmStrnIsUpper(“ABCdef”, 8);    /* after null position */
    /* rc == FALSE */
    
    rc = pfmStrnIsUpper(“”, 8);
    /* rc == FALSE */

6. pfmStrIsAlpha

Checks whether all characters in a null-terminated string are alphabet.

  • Prototype

    long pfmStrIsAlpha(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are alphabet.

    FALSE

    The string includes a chatacter that is not alphabet, or its first character is null.

  • Example

    char     MIXED_STR[]      = “     abcDEF @#$! 1. 23hljk   “;
    char     ALPHA_ONLY[]     = “abcDEF”;
    char     ALPHA_SPACE[]    = “    ab cDef     “
    char     ALPHA_RSPACE[]   = “abcDef     “
    char     ALPHA_NUM[]      = “abcDEF123hljk”
    
    rc = pfmStrIsAlpha(MIXED_STR);
    /* rc == FALSE */
    
    rc = pfmStrIsAlpha(ALPHA_ONLY);
    /* rc == TRUE */
    
    rc = pfmStringIsAlphabetic(ALPHA_SPACE);
    /* rc == FALSE */
    
    rc = pfmStrIsAlpha(ALPHA_RSPACE);
    /* rc == FALSE */
    
    rc = pfmStrIsAlpha(ALPHA_NUM);
    /* rc == FALSE */
    
    rc = pfmStrIsAlpha(“”);
    /* rc == FALSE */

7. pfmStrnIsAlpha

Checks whether all characters in a fixed-length string are alphabet.

  • Prototype

    long pfmStrnIsAlpha(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are alphabet.

    FALSE

    The string includes a chatacter that is not alphabet, or its first character is null.

  • Example

    char     MIXED_STR[] = “     abcDEF @#$! 1. 23hljk   “;
    char     ALPHA_ONLY[] = “abcDEF”;
    char     ALPHA_RSPACE[] = “abcDef     “
    char     ALPHA_NUM[] = “abcDEF123hljk”
    
    rc = pfmStrnIsAlpha(MIXED_STR, (int)strlen(MIXED_STR));
    /* rc == FALSE */
    
    rc = pfmStrnIsAlpha(ALPHA_ONLY, (int)strlen(ALPHA_ONLY));
    /* rc == TRUE */
    
    rc = pfmStrnIsAlpha(ALPHA_ONLY, (int)strlen(ALPHA_ONLY) + 1000);
    /* rc == TRUE */
    
    rc = pfmStrnIsAlpha(ALPHA_RSPACE, 5);
    /* rc == TRUE */
    
    rc = pfmStrnIsAlpha(ALPHA_NUM, 10);    /* null position */
    /* rc == FALSE */
    
    rc = pfmStrnIsAlpha(ALPHA_NUM, 5);    /* after null position */
    /* rc == TRUE */
    
    rc = pfmStrnIsAlpha(“”, 8);
    /* rc == FALSE */

8. pfmStrIsAlphaNumeric

Checks whether all characters in a null-terminated string are alphabet or digits.

  • Prototype

    long pfmStrIsAlphaNumeric(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are alphabet or digits.

    FALSE

    The string includes a chatacter that is not alphabet or a digit.

  • Example

    char     MIXED_STR[] = “     abcDEF @#$! 1. 23hljk   “;
    char     ALPHA_NUM[] = “abcDEF123hljk”
    
    rc = pfmStrIsAlphaNumeric(MIXED_STR);
    /* rc == FALSE */
    
    rc = pfmStrIsAlphaNumeric(ALPHA_NUM);
    /* rc == TRUE */
    
    rc = pfmStrIsAlphaNumeric(“”);
    /* rc == FALSE */

9. pfmStrnIsAlphaNumeric

Checks whether all characters in a fixed-length string are alphabet or digits.

  • Prototype

    long pfmStrnIsAlphaNumeric(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are alphabet or digits.

    FALSE

    The string includes a chatacter that is not alphabet or a digit.

  • Example

    char     MIXED_STR[] = “     abcDEF @#$! 1. 23hljk   “;
    char     ALPHA_NUM[] = “abcDEF123hljk”
    
    rc = pfmStrnIsAlphaNumeric(MIXED_STR, (int)strlen(MIXED_STR));
    /* rc == FALSE */
    
    rc = pfmStrnIsAlphaNumeric(MIXED_STR, 5);
    /* rc == FALSE */
    
    rc = pfmStrnIsAlphaNumeric(ALPHA_NUM, (int)strlen(ALPHA_NUM));
    /* rc == TRUE */
    
    rc = pfmStrnIsAlphaNumeric(ALPHA_NUM, (int)strlen(ALPHA_NUM) + 1000);
    /* rc == TRUE */
    
    rc = pfmStrnIsAlphaNumeric(“”, 8);
    /* rc == FALSE */

10. pfmStrIsNull

Checks whether the first character of a string is null ('\0').

  • Prototype

    long pfmStrIsNull(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    The first character of the string is null ('\0').

    FALSE

    The first character of the string is not null ('\0').

  • Example

    char     STR_NULL[]        = “\0\0\0\0\0\0”
    char     STR_NULL _ALPHA[] = “\0\0ABC\0\0\0”
    
    rc = pfmStrIsNull(STR_NULL);
    /* rc == TRUE */
    
    rc = pfmStrIsNull(STR_NULL _ALPHA);
    /* rc == TRUE */
    
    rc = pfmStrIsNull(“GH”);
    /* rc == FALSE */
    
    rc = pfmStrIsNull(“”);
    /* rc == TRUE */

11. pfmStrnIsNull

Checks whether all characters in a string are null ('\0').

  • Prototype

    long pfmStrnIsNull(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are null.

    FALSE

    The string inlcudes a character that is not null.

  • Example

    char     STR_NULL[]        = “\0\0\0\0\0\0”
    char     STR_NULL _ALPHA[] = “\0\0ABC\0\0\0”
    
    rc = pfmStrnIsNull(STR_NULL, (int)sizeof(STR_NULL));
    /* rc == TRUE */
    
    rc = pfmStrnIsNull(STR_NULL _ALPHA, (int)sizeof(STR_NULL _ALPHA));
    /* rc == FALSE */
    
    rc = pfmStrnIsNull(“GH”, (int)sizeof(“GH”));
    /* rc == FALSE */
    
    rc = pfmStrnIsNull(“”, 8);
    /* rc == TRUE */

12. pfmStrIsNumber

Checks whether all characters in a null-terminated string are digits.

  • Prototype

    long pfmStrIsNumber(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are digits.

    FALSE

    The string includes a chatacter that is not a digit.

  • Example

    char     STR_NUM[]        = “0123456789”
    
    rc = pfmStrIsNumber(STR_NUM);
    /* rc == TRUE */
    
    rc = pfmStrIsNumber(“”);
    /* rc == FALSE */

13. pfmStrnIsNumber

Checks whether all characters in a fixed-length string are digits.

  • Prototype

    long pfmStrnIsNumber(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are digits.

    FALSE

    The string includes a chatacter that is not a digit.

  • Example

    char     STR_NUM[]        = “0123456789”
    
    rc = pfmStrnIsNumber(STR_NUM, (int)strlen(STR_NUM));
    /* rc == TRUE */
    
    rc = pfmStrnIsNumber(“”, 8);
    /* rc == FALSE */

14. pfmStrIsSpace

Checks whether all characters in a null-terminated string are spaces.

  • Prototype

    long pfmStrIsSpace(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are spaces or null.

    FALSE

    The string includes a chatacter that is not a space or null.

  • Example

    char     STR_SPACE[]              = “                    ”
    char     STR_SPACE_ALPHA[]        = “                    abc”
    char     STR_ALPHA_SPACE[]        = “asdf              abc”
    
    rc = pfmStrIsSpace(STR_SPACE);
    /* rc == TRUE */
    
    rc = pfmStrIsSpace(STR_SPACE_ALPHA);
    /* rc == FALSE */
    
    rc = pfmStrIsSpace(STR_ALPHA_SPACE);
    /* rc == FALSE */
    
    rc = pfmStrIsSpace(“”);
    /* rc == FALSE */

15. pfmStrnIsSpace

Checks whether all characters in a fixed-length string are spaces.

  • Prototype

    long pfmStrnIsSpace(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are spaces or null.

    FALSE

    The string includes a chatacter that is not a space or null.

  • Example

    char     STR_SPACE[]       = “                    ”
    char     STR_SPACE_ALPHA[] = “                    abc”
    
    rc = pfmStrnIsSpace(STR_SPACE, (int)strlen(STR_SPACE));
    /* rc == TRUE */
    
    rc = pfmStrnIsSpace(STR_SPACE_ALPHA, (int)strlen(STR_SPACE));
    /* rc == TRUE */
    
    rc = pfmStrnIsSpace(STR_SPACE_ALPHA, (int)strlen(STR_SPACE_ALPHA));
    /* rc == FALSE */
    
    rc = pfmStrnIsSpace(“”, 8);
    /* rc == FALSE */

16. pfmStrIsSpaceNull

Checks whether all characters in a null-terminated string are spaces or whether the first character is null.

  • Prototype

    long pfmStrIsSpaceNull(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are spaces or the first string is null.

    FALSE

    The string includes a chatacter that is not a space or the first character is not null.

  • Example

    char     STR_SPACE[]       = “                    ”
    char     STR_SPACE_ALPHA[] = “                    abc”
    char     STR_ALPHA_SPACE[] = “asdf              abc”
    
    rc = pfmStrIsSpaceNull(“\0\0\0”);
    /* rc == TRUE */
    
    rc = pfmStrIsSpaceNull(STR_SPACE);
    /* rc == TRUE */
    
    rc = pfmStrIsSpaceNull(STR_SPACE_ALPHA);
    /* rc == FALSE */
    
    rc = pfmStrIsSpaceNull(STR_ALPHA_SPACE);
    /* rc == FALSE */
    
    rc = pfmStrIsSpaceNull(“”);
    /* rc == FALSE */

17. pfmStrnIsSpaceNull

Checks whether all characters in a fixed-length string are spaces or whether the first character is null.

  • Prototype

    long pfmStrnIsSpaceNull(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are spaces or the first string is null.

    FALSE

    The string includes a chatacter that is not a space or the first character is not null.

  • Example

    char     STR_SPACE[]       = “                    ”
    char     STR_SPACE_ALPHA[] = “                    abc”
    
    rc = pfmStrnIsSpaceNull(“\0\0\0”, 3);
    /* rc == TRUE */
    
    rc = pfmStrnIsSpaceNull(STR_SPACE, (int)strlen(STR_SPACE));
    /* rc == TRUE */
    
    rc = pfmStrnIsSpaceNull(STR_SPACE_ALPHA,
    (int)strlen(STR_SPACE_ALPHA) - 3);
    /* rc == TRUE */
    
    rc = pfmStrnIsSpaceNull(STR_SPACE_ALPHA,
    (int)strlen(STR_SPACE_ALPHA));
    /* rc == FALSE */
    
    
    rc = pfmStrnIsSpaceNull(“”, 8);
    /* rc == TRUE */

18. pfmStrIsZero

Checks whether all characters in a null-terminated string are 0.

  • Prototype

    long pfmStrIsZero(char *str);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are 0.

    FALSE

    The string includes a chatacter that is not 0.

  • Example

    rc = pfmStrIsZero(“000000000000”);
    /* rc == TRUE */
    
    rc = pfmStrIsZero(“”);
    /* rc == FALSE */

19. pfmStrnIsZero

Checks whether all characters in a fixed-length string are 0.

  • Prototype

    long pfmStrnIsZero(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are 0.

    FALSE

    The string includes a chatacter that is not 0.

  • Example

    rc = pfmStrnIsZero(“00000”, 5);
    /* rc == TRUE */
    
    rc = pfmStrnIsZero(“000001234”, 5);
    /* rc == TRUE */
    
    rc = pfmStrnIsZero(“000001234”, 7);
    /* rc == FALSE */
    
    rc = pfmStrnIsZero(“”, 8);
    /* rc == FALSE */

20. pfmStrIsValidDigit

Checks whether a given registration number or corporate registration number is valid.

  • Prototype

    long  pfmStrIsValidDigit(long fn_code, char *in_str, long str_len);
  • Parameters

    Parameter Description

    fn_code (input)

    • PFM_VALID_DIGIT_CHK_ID_NO: Resident registration number.

    • PFM_VALID_DIGIT_CHK_CMPY_NO: Corporate registration number.

    *in_str (input)

    String to check.

    str_len (input)

    Length of in_str.

  • Return values

    Return Value Description

    TRUE

    The input string is valid.

    FALSE

    The input string is not valid.

  • Example

    rc = pfmStrIsValidDigit (PFM_VALID_DIGIT_CHK_ID_NO, “00000”, 5);
    /* rc == TRUE */

21. pfmStrIsKsc

Checks whether all characters in a null-terminated string are Korean characters.

You can treat a non-Korean character as a Korean character by using the opt parameter. Multiple characters can be specified in the parameter.

  • Prototype

    long pfmStrIsKsc(char *src, char *opt);
  • Parameters

    Parameter Description

    *src (input)

    String to check.

    *opt (input)

    Options. Any character used as its argument is also treated as a Korean character.

    • A: Treats an alphabet as a Korean character.

    • N: Treats a digit as a Korean character.

    • S: Treats a space (0x20) as a Korean character.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are Korean characters.

    FALSE

    The string includes a chatacter that is not a Korean character.

    RC_ERR

    The length of opt exceeds 10, or the argument of opt is invalid.

  • Example

    char   str[]  =  “13층의 A사장은 좋다”;
    long   rc;
    
    rc = pfmStrIsKsc(str, “A”);
    if(rc == FALSE) {
       PFM_ERR(“A non-Korean character is included.”);
       return RC_ERR;
    }
    else if(rc == RC_ERR) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    String Option Return Value

    ”13층의 A사장은 좋다”

    ” ”

    FALSE

    ”A”

    FALSE

    ”AN”

    FALSE

    ”SN”

    FALSE

    ”ANS”

    TRUE

22. pfmStrnIsKsc

Checks whether all characters in a fixed-length string are Korean characters.

You can treat a non-Korean character as a Korean character by using the opt parameter. Multiple characters can be specified in the parameter.

  • Prototype

    long pfmStrnIsKsc(char *src, long len, char *opt);
  • Parameters

    Parameter Description

    *src (input)

    String to check.

    len (input)

    String length.

    *opt (input)

    Options. Any character used as its argument is also treated as a Korean character.

    • A: Treats an alphabet as a Korean character.

    • N: Treats a digit as a Korean character.

    • S: Treats a space (0x20) as a Korean character.

  • Return values

    Return Value Description

    TRUE

    All characters in the string are Korean characters.

    FALSE

    The string includes a chatacter that is not a Korean character.

    RC_ERR

    The string is null, or the argument of len is less than 0.

  • Example

    char   str[20 + 1]  =  “KOREA에오신걸환영합니다”;
    long   rc;
    
    rc = pfmStrnIsKsc(str, 20, “A”);
    if(rc == FALSE) {
       PFM_ERR(“A non-Korean character is included.”);
       return RC_ERR;
    }
    else if(rc == RC_ERR)
    {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

23. pfmStrnIsKorean

Checks whether a string has at least one Korean character.

  • Prototype

    long pfmStrnIsKorean(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    String to check.

    len (input)

    String length.

  • Return values

    Return Value Description

    TRUE

    The string has at least one Korean character.

    FALSE

    The string has no Korean character.

    RC_ERR

    The string is null, or the argument of len is less than 0.

  • Example

    char   str[100 + 1]  =  “KOREA에오신걸환영합니다”;
    long   rc;
    
    rc = pfmStrnIsKorean(str, strlen(str));
    if(rc == TRUE) {
       PFM_ERR(“At least one Korean character is included.”);
       return RC_ERR;
    }
    else if(rc == RC_ERR)
    {
    PFM_ERR(“%s”, pfmStrGetErrorMsg()););
       return RC_ERR;
    }

24. pfmStrLTrim

Trims left spaces of a null-terminated string.

  • Prototype

    char * pfmStrLTrim(char *str);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

  • Return values

    Returns a pointer to the result string whose left spaces are trimmed.

  • Example

    char   STR[]        =  “     abcDEF  1. 23hljk     ”;
    char   STR_LTRIM[]  =  “abcDEF  1. 23hljk     ”;
    char   SPACE[]      = “                          “
    char   STR_EMPTY[]  = “”;
    
    strncpy(ostr, pfmStrLTrim(STR), sizeof(STR));
    /* ostr == STR_LTRIM */
    
    strncpy(ostr, pfmStrLTrim(SPACE), sizeof(SPACE));
    /* ostr == STR_EMPTY */

25. pfmStrnLTrim

Trims left spaces of a fixed-length string.

  • Prototype

    char * pfmStrnLTrim(char *str, long len);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

    len (input)

    String length.

  • Return values

    Returns a pointer to the result string whose left spaces are trimmed.

  • Example

    char   STR[]       =  “     abcDEF  1. 23hljk     ”;
    char   STR_LTRIM[] =  “abcDEF  1. 23hljk     ”;
    char   SPACE[]     = “                          “
    char   STR_EMPTY[] = “”;
    
    strncpy(ostr, pfmStrnLTrim(STR, sizeof(STR)), sizeof(STR));
    /* ostr == STR_LTRIM */
    
    strncpy(ostr, pfmStrnLTrim(SPACE, sizeof(SPACE)), sizeof(SPACE));
    /* ostr == STR_EMPTY[] */

26. pfmStrRTrim

Trims right spaces of a null-terminated string.

  • Prototype

    char * pfmStrRTrim(char *str);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

  • Return values

    Returns a pointer to the result string whose right spaces are trimmed.

  • Example

    char   STR[]       =  “     abcDEF  1. 23hljk     ”;
    char   STR_RTRIM[] =  “     abcDEF  1. 23hljk”;
    char   SPACE[]     = “                          “
    char   STR_EMPTY[] = “”;
    
    strncpy(ostr, pfmStrRTrim(STR), sizeof(STR));
    /* ostr == STR_RTRIM */
    
    strncpy(ostr, pfmStrRTrim(SPACE), sizeof(SPACE));
    /* ostr == STR_EMPTY */

27. pfmStrnRTrim

Trims right spaces of a fixed-length string.

  • Prototype

    char * pfmStrnRTrim(char *str, long len);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

    len (input)

    String length.

  • Return values

    Returns a pointer to the result string whose right spaces are trimmed.

  • Example

    char   STR[]       =  “     abcDEF  1. 23hljk     ”;
    char   STR_RTRIM[] =  “     abcDEF  1. 23hljk”;
    char   SPACE[]     = “                          “
    char   STR_EMPTY[] = “”;
    
    strncpy(ostr, pfmStrnRTrim(STR, sizeof(STR)), sizeof(STR));
    /* ostr == STR_RTRIM */
    
    strncpy(ostr, pfmStrnRTrim(SPACE, sizeof(SPACE)), sizeof(SPACE));
    /* ostr == STR_EMPTY */

28. pfmStrTrim

Trims left and right spaces of a null-terminated string.

  • Prototype

    char * pfmStrTrim(char *str);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

  • Return values

    Returns a pointer to the result string whose left and right spaces are trimmed.

  • Example

    char   STR[]       =  “     abcDEF  1. 23hljk     ”;
    char   STR_TRIM[]  =  “abcDEF  1. 23hljk”;
    char   SPACE[]     = “                          “
    char   STR_EMPTY[] = “”;
    
    strncpy(ostr, pfmStrTrim(STR), sizeof(STR));
    /* ostr == STR_TRIM */
    
    strncpy(ostr, pfmStrTrim(SPACE), sizeof(SPACE));
    /* ostr == STR_EMPTY */

29. pfmStrnTrim

Trims left and right spaces of a fixed-length string.

  • Prototype

    char * pfmStrnTrim(char *str, long len);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

    len (input)

    String length.

  • Return values

    Returns a pointer to the result string whose left and right spaces are trimmed.

  • Example

    char   STR[]       =  “     abcDEF  1. 23hljk     ”;
    char   STR_TRIM[]  =  “abcDEF  1. 23hljk”;
    char   SPACE[]     = “                          “
    char   STR_EMPTY[] = “”;
    
    strncpy(ostr, pfmStrnTrim(STR, sizeof(STR)), sizeof(STR));
    /* ostr == STR_TRIM */
    
    strncpy(ostr, pfmStrnTrim(SPACE, sizeof(SPACE)), sizeof(SPACE));
    /* ostr == STR_EMPTY */

30. pfmStrRemoveSpace

Removes spaces (0x20) from a null-terminated string.

  • Prototype

    char * pfmStrRemoveSpace(char *str);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

  • Return values

    Returns a pointer to the result string whose spaces are removed.

  • Example

    char   str[]    =  “ A B C ”;
    
    pfmStrRemoveSpace(str);
    /* str == “ABC” */

31. pfmStrnRemoveSpace

Removes spaces (0x20) from a fixed-length string.

  • Prototype

    char * pfmStrnRemoveSpace(char *str, long len);
  • Parameters

    Parameter Description

    *str (input/output)

    String to check.

    len (input)

    String length.

  • Return values

    Returns a pointer to the result string whose spaces are removed.

  • Example

    char   str[]   =  “ A B C ”;
    char   str2[]  =  “ A B C ”;
    
    pfmStrnRemoveSpace(str, 10);
    /* str == “ABC” */
    
    pfmStrnRemoveSpace(str2, 3);
    /* str2 == “A” */

32. pfmStrCmpLTrim

Trims left spaces of two strings and then compares them.

  • Prototype

    long pfmStrCmpLTrim(char *str1, char *str2, long len);
  • Parameters

    Parameter Description

    *str1 (input)

    First string to compare.

    *str2 (input)

    Second string to compare.

    len (input)

    Length of the part of the strings to compare.

  • Return values

    Returns 0 if the two strings whose left spaces are trimmed are the same. Returns a positive number if the two strings whose left spaces are trimmed are not the same and the ASCII value of the first different character in the first string is greater than that in the second string. Returns a negative value if they are not the same and the ASCII value of the first different character in the first string is less than that in the second string.

  • Example

    rc = pfmStrCmpLTrim(“     TEST”, “TEST”, 4);
    /* Comparing “TEST” and “TEST”: rc == 0 */
    
    rc = pfmStrCmpLTrim(“     123”, “     234”, 3);
    /* Comparing “123” and “234”: rc < 0 */

33. pfmStrCmpRTrim

Trims right spaces of two strings and then compares them.

  • Prototype

    long pfmStrCmpRTrim(char *str1, char *str2, long len);
  • Parameters

    Parameter Description

    *str1 (input)

    First string to compare.

    *str2 (input)

    Second string to compare.

    len (input)

    Length of the part of the strings to compare.

  • Return values

    Returns 0 if the two strings whose right spaces are trimmed are the same. Returns a positive number if the two strings whose right spaces are trimmed are not the same and the ASCII value of the first different character in the first string is greater than that in the second string. Returns a negative value if they are not the same and the ASCII value of the first different character in the first string is less than that in the second string.

  • Example

    rc = pfmStrCmpRTrim(“TEST”, “TEST     ”, 4);
    /* Comparing “TEST” and “TEST”: rc == 0 */
    
    rc = pfmStrCmpRTrim(“123     ”, “234     ”, 3);
    /* Comparing “123” and “234”: rc < 0 */

34. pfmStrCmpTrim

Trims left and right spaces of two strings and then compares them.

  • Prototype

    long  pfmStrCmpTrim(char *str1, char *str2, long len);
  • Parameters

    Parameter Description

    *str1 (input)

    First string to compare.

    *str2 (input)

    Second string to compare.

    len (input)

    Length of the part of the strings to compare.

  • Return values

    Returns 0 if the two strings whose left and right spaces are trimmed are the same. Returns a positive number if the two strings whose left and right spaces are trimmed are not the same and the ASCII value of the first different character in the first string is greater than that in the second string. Returns a negative value if they are not the same and the ASCII value of the first different character in the first string is less than that in the second string.

  • Example

    rc = pfmStrCmpTrim(“     TEST”, “TEST               ”, 10);
    /* Comparing "TEST" and "TEST": rc == 0 */
    
    rc = pfmStrCmpTrim(“     123     ”, “     234     ”, 10);
    /* Comparing "TEST" and "TEST": rc < 0 */

35. pfmStrCmpRemoveSpace

Removes spaces (0x20) of two strings and then compares them.

  • Prototype

    long pfmStrCmpRemoveSpace(char *str1, char *str2, long len);
  • Parameters

    Parameter Description

    *str1 (input)

    First string to compare.

    *str2 (input)

    Second string to compare.

    len (input)

    Length of the part of the strings to compare.

  • Return values

    Returns 0 if the two strings whose spaces are removed are the same. Returns a positive number if the two strings whose spaces are removed are not the same and the ASCII value of the first different character in the first string is greater than that in the second string. Returns a negative value if they are not the same and the ASCII value of the first different character in the first string is less than that in the second string.

  • Example

    char   str1[12 + 1]  =  “20051028”;
    char   str2[12 + 1]  =  “2005 10 28”;
    
    if(pfmStrCmpRemoveSpace(str1, str2, 12) == 0) {
       PFM_DBG(“The two dates are the same.”);
    }

36. pfmStrCpyRPadSpace

Copies a string as long as specifed and pads the ending remaining part with spaces (0x20).

  • Prototype

    long pfmStrCpyRPadSpace(char *dest, char *src, long len);
  • Parameters

    Parameter Description

    *dest (output)

    Result string.

    *src (input)

    String to copy.

    len (input)

    Lengh of the string to copy.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   dest[9];
    char   src[]  =  “abcde”;
    long   rc;
    
    rc = pfmStrCpyRPadSpace(dest, src, sizeof(dest));
    if(rc == RC_ERR) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    /* dest == “abcde      ” */

37. pfmStrCpyRPadZero

Copies a string as long as specifed, justifies it right, and pads the starting remaining part with 0.

  • Prototype

    long pfmStrCpyRPadZero(char *dest, char *src, long len);
  • Parameters

    Parameter Description

    *dest (output)

    Result string.

    *src (input)

    String to copy.

    len (input)

    Lengh of the string to copy.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   dest[9];
    char   src[]  =  ”12345”;
    long   rc;
    
    memset(dest, 0x00, sizeof(dest));
    
    rc = pfmStrCpyRPadZero(dest, src, sizeof(dest));
    if(rc == RC_ERR) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    /* dest == “000012345” */

38. pfmStrCpySkip

Removes a specified character from a string and copies it to another string.

  • Prototype

    long pfmStrCpySkip(char *dest, char *src, char toskip, long dest_len);
  • Parameters

    Parameter Description

    *dest (output)

    Result string.

    *src (input)

    String to copy.

    toskip (input)

    Character to remove.

    dest_len (input)

    Length of the result string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   ostr[32];
    long   rc;
    
    rc = pfmStrCpySkip(ostr, “123kyj456”, ‘k’, 9);
    /* ostr == “123yj456” */
    rc = pfmStrCpySkip(ostr, “123kyj456”, ‘k’, 5);
    /* rc == RC_ERR Error if the buffer size is less than the result string length. */
    
    rc = pfmStrCpySkip(ostr, “a/b/c/d/e/f/g/”, ‘/’, 32);
    /* ostr == “abcdefg” */
    
    rc = pfmStrCpySkip(ostr, “a-b-c-d-e-f-g-”, ‘-’, 32);
    /* ostr == “abcdefg” */
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

39. pfmStrExtractDigitN

Extracts digits from a null-terminated string and converts them to an integer string.

  • Prototype

    long pfmStrExtractDigitN(char *dest, long dest_len, char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Integer string.

    dest_len (input)

    Length of the integer string.

    *src (input)

    Null-terminated string.

    src_len (input)

    Length of the null-terminated string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[] = “345 67/33.8-4890/”;
    char   dest[100];
    long   rc;
    
    rc = pfmStrExtractDigitN(dest, 100, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    /* Normwl conversion: dest = “345673383890” */

40. pfmStrCmpMulti

Compares a string with a base string.

  • Prototype

    long pfmStrCmpMulti(char *str, …);
  • Parameters

    Parameter Description

    *str (input)

    Base string.

    … (input)

    String to compare. An empty string (“”) indicates the last parameter.

  • Return values

    Returns the string’s position where the base string is located if the base string is found. Returns 0 if the base string is not found.

  • Example

    char   key[] = “test_n”;
    long   rc;
    
    rc = pfmStrCmpMulti (key, “test”, “n”, “asdf”, “ccsd”, “test_n”, “”);
    if(rc != 1) {
          return RC_ERR;
    }

41. pfmStrGetIndex

Searches a base string from N null-terminated strings.

  • Prototype

    long pfmStrGetIndex(long cnt, char *str, …);
  • Parameters

    Parameter Description

    cnt (input)

    Number of strings to compare.

    *str (input)

    Base string.

    … (input)

    String to compare.

  • Return values

    Returns the number (1,2, …., cnt) of the string where the base string exists. Returns 0 if the base string is not found.

  • Example

    rc = pfmStrGetIndex(4, “a”, “a”, “ab”, “abc”, “abcd”);
    /* rc == 1 */
    
    rc = pfmStrGetIndex(4, “ab”, “a”, “ab”, “abc”, “abcd”);
    /* rc == 2 */
    
    rc = pfmStrGetIndex(4, “abc”, “a”, “ab”, “abc”, “abcd”);
    /* rc == 3 */
    
    rc = pfmStrGetIndex(4, “abcd”, “a”, “ab”, “abc”, “abcd”);
    /* rc == 4 */
    
    rc = pfmStrGetIndex(4, “abcde”, “a”, “ab”, “abc”, “abcd”);
    /* rc == 0 */

42. pfmToLower

Converts a null-terminated string to lowercase regardless of its length.

  • Prototype

    char * pfmToLower(char *str);
  • Parameters

    Parameter Description

    *str (input/output)

    String to convert.

  • Return values

    Returns a pointer to the converted string through *str.

  • Example

    char     istr[256], ostr[256];
    char     STR_MIXED[] =  “AaBbCc123Dd EeFf”;
    char     STR_LOWER[] =  “aabbcc123dd eeff”;
    
    strncpy(istr, STR_MIXED, strlen(STR_MIXED));
    strncpy(ostr, pfmToLower(istr), strlen(STR_LOWER));
    /* Bothe istr and ostr are STR_LOWER. */
    
    strncpy(ostr, pfmToLower(“ABCDEFG”), 7);
    /* ostr is “abcdefg”. */

43. pfmToLowern

Converts a fixed-length string to lowercase.

  • Prototype

    char * pfmToLowern(char *str, long len);
  • Parameters

    Parameter Description

    *str (input/output)

    String to convert.

    len (input)

    String length.

  • Return values

    Returns a pointer to the converted string through *str.

  • Example

    char     istr[256];
    char     STR_MIXED1[]   =  “AAABBBB”;
    char     STR_LOWER1[]   =  “aaaBBBB”;
    char     STR_MIXED3[]   =  “AAABBBB”;
    
    pfmToLowern(STR_MIXED1, 3);
    /* STR_MIXED1 is the same as STR_LOWER1. */
    
    strncpy(istr, pfmToLowern(STR_MIXED3, 3), 7);
    /* STR_MIXED3 is converted to “aaaBBBB” and then this converted string is copied to istr. */

44. pfmUpper

Converts a null-terminated string to uppercase regardless of its length.

  • Prototype

    char * pfmToUpper(char *str);
  • Parameters

    Parameter Description

    *str (input/output)

    String to convert.

  • Return values

    Returns a pointer to the converted string through *str.

  • Example

    char     istr[BUF_SIZE], ostr[BUF_SIZE];
    char     STR_MIXED[]  =  “AaBbCc123Dd EeFf”;
    char     STR_UPPER[]  =  “AABBCC123DD EEFF”;
    
    strncpy(istr, STR_MIXED, strlen(STR_MIXED));
    strncpy(ostr, pfmStrToUpper(istr), strlen(STR_MIXED));
    /* Both istr and ostr are STR_UPPER. */
    
    strncpy(ostr, pfmStrToUpper(“abcdefg”), 7);
    /* ostr is “ABCDEFG”. */

45. pfmToUppern

Converts a fixed-length string to uppercase.

  • Prototype

    char * pfmToUppern(char *str, long len);
  • Parameters

    Parameter Description

    *str (input/output)

    String to convert.

    len (input)

    String length.

  • Return values

    Returns a pointer to the converted string through *str.

  • Example

    char     istr[256];
    char     STR_MIXED1[]  =  “aaaBBBB”;
    char     STR_LOWER1[]  =  “AAABBBB”;
    char     STR_MIXED3[]  =  “aaaBBBB”;
    
    pfmToUppern(STR_MIXED1, 3);
    /* STR_MIXED1 is the same as STR_LOWER1. */
    
    strncpy(istr, pfmToUppern(STR_MIXED3, 3), 7);
    /* STR_MIXED3 is converted to “AAABBBB” and then this converted string is copied to istr. */

46. pfmAscToInt

Converts a string to Int type.

  • Prototype

    int pfmAscToInt(char *ptr, long len);
  • Parameters

    Parameter Description

    *ptr (input)

    String to convert.

    len (input)

    String length.

  • Return values

    Returns the Int value.

  • Example

    int   num;
    
    num = pfmAscToInt(“1234”, 4);
    /* num == 1234 */
    
    num = pfmAscToInt(“1234”, 3);
    /* num == 123 */

47. pfmAscToLong

Converts a string to Long type.

  • Prototype

    long pfmAscToLong(char *ptr, long len);
  • Parameters

    Parameter Description

    *ptr (input)

    String to convert.

    len (input)

    String length.

  • Return values

    Returns the Long value.

  • Example

    long   lnum;
    
    lnum = pfmAscToLong(“1234567890”, 10);
    /* lnum == 1234567890 */
    
    lnum = pfmAscToLong(“1234567890”, 6);
    /* lnum == 123456 */

48. pfmStrToLong

Converts a null-terminated string to Long type.

  • Prototype

    long pfmStrToLong(long *num, char *str);
  • Parameters

    Parameter Description

    *num (output)

    Pointer to the converted Long value.

    *str (input)

    String to convert.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   str[]  =  “2315”;
    long   num, rc;
    
    rc = pfmStrToLong(&num, str);
    /* num == 2315 */
    if(rc == RC_ERR) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

49. pfmStrnToLong

Converts a fixed-length string to Long type.

  • Prototype

    long pfmStrnToLong(long *num, char *str, long len);
  • Parameters

    Parameter Description

    *num (output)

    Pointer to the converted Long value.

    *str (input)

    String to convert.

    len (input)

    Length of the string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   str[]  =  “2315”;
    long   num, rc;
    
    rc = pfmStrnToLong(&num, str, 4);
    /* num == 2315 */
    
    rc = pfmStrnToLong(&num, str, 3);
    /* num == 231 */
    
    rc = pfmStrnToLong(&num, str, 2);
    /* num == 23 */
    
    rc = pfmStrnToLong(&num, “123a”, 4);
    if(rc == RC_ERR) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

50. pfmLongToStrn

Converts a Long number to a string.

  • Prototype

    long pfmLongToStrn(char *str, long num, long buf_size);
  • Parameters

    Parameter Description

    *str (output)

    Converted string.

    num (input)

    Long number.

    buf_size (input)

    Size of the buffer for the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    The size of the converted string exceeds that of the buffer.

  • Example

    rc = pfmLongToStrn(ostr, 123456, 10);
    /* ostr == “123456” */
    
    rc = pfmLongToStrn(ostr, 12345678, 10);
    /* ostr == “12345678” */
    
    rc = pfmLongToStrn(ostr, 12345678, 6);
    /* rc == RC_ERR */
    if(rc == RC_ERR) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

51. pfmLongToStrnLpadZero

Converts a Long number to a string, aligns it to the right, and pads spaces with 0.

  • Prototype

    long pfmLongToStrnLpadZero(char *str, long num, long buf_size);
  • Parameters

    Parameter Description

    *str (output)

    Converted string.

    num (input)

    Long number.

    buf_size (input)

    Length of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    The size of the converted string exceeds that of the buffer.

  • Example

    rc = pfmLongToStrnLpadZero(ostr, 123456, 10);
    /* rc == RC_NRM, ostr == “0000123456” */
    
    rc = pfmLongToStrnLpadZero(ostr, 12345678, 10);
    /* rc == RC_NRM, ostr == “0012345678” */
    
    rc = pfmLongToStrnLpadZero(ostr, 12345678, 6);
    /* rc == RC_ERR */
    if(rc == RC_ERR) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

52. pfmStrAddLong

Adds a Long integer to a given string and then converts it to a string.

  • Prototype

    long pfmStrAddLong(char *str, long num);
  • Parameters

    Parameter Description

    *str (input/output)

    Input/output string.

    num (input)

    Long integer to add.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    The length of the string after the addition exceeds that of the original string.

  • Example

    char   str[32]  = “100”;
    long   num      = 11;
    long   rc       = RC_NRM;
    
    rc = pfmStrAddLong(str, num);
    /* str == “111” */
    strncpy(str, “999”, 3);
    rc = pfmStrAddLong(str, 10);     /* 999 + 10 == 1009 */
    /* Because rc == RC_ERR, strlen(“999”) < strlen(“1009”) */
    
    strncpy(str, “1”, 2);
    rc = pfmStrAddLong(str, -3);     /* 1 + (-3) == -2 */
    /* Because rc == RC_ERR, strlen(“1”) < strlen(“-3”) */
    
    strncpy(str, “-999”, 4);
    rc = pfmStrAddLong(str, 1000);     /* -999 + 1000 == 1 */
    /* rc == “0001”, 0 padding for leading digits */
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

53. pfmStrSubLong

Subtracts a Long integer from a given string and then converts it to a string.

  • Prototype

    long pfmStrSubLong(char *str, long num);
  • Parameters

    Parameter Description

    *str (input/output)

    Input/output string.

    num (input)

    Long integer to subtract.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    The length of the string after the subtraction exceeds that of the original string.

  • Example

    char   str[32]  =  “100”;
    long   num      = 11;
    long   rc       = RC_NRM;
    
    rc = pfmStrSubLong(str, num);
    /* str == “089”, 0 padding for leading digits */
    
    strncpy(str, “40”, 2);
    rc = pfmStrSubLong(str, 77);     /* 40 - 77 == -37 */
    /* Because rc == RC_ERR, strlen(“40”) < strlen(“-37”) */
    
    strncpy(str, “10000”, 5);
    rc = pfmStrSubLong(str, 9900);  /* 10000 - 9900 == 100 */
    /* rc == “00100”, 0 padding for leading digits */
    
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

54. pfmStrToHex

Converts a null-terminated string to hexadecimal.

  • Prototype

    long pfmStrToHex(char *hex, long hex_len, char *str, long in_len);
  • Parameters

    Parameter Description

    *hex (output)

    Converted string.

    hex_len (input)

    Length of the converted string.

    *str (input)

    String to convert.

    in_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   hex[32];
    long   rc;
    
    rc = pfmStrToHex(hex, 32, “jkfl43a-gg”, 32);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    /* 6a 6b 66 6c 34 33 61 2d 67 67 */

55. pfmStrAscToEbc

Converts an ASCII string to EBCDIC.

  • Prototype

    long pfmStrAscToEbc (unsigned char *dest, unsigned  char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “abcdefg”;
    char   dest[20 + 1];
    long   len;
    
    rc = pfmStrAscToEbc(desc, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

56. pfmStrEbcToAsc

Converts an EBCDIC string to ASCII.

  • Prototype

    long pfmStrEbcToAsc(unsigned char *dest, unsigned  char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “\201\202\203\204\205\206\207”;
    char   dest[20 + 1];
    
    rc = pfmStrEbcToAsc(dest, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

57. pfmStrEngToKsc

Converts English code to KSC5601.

  • Prototype

    long pfmStrEngToKsc(unsigned char *dest, unsigned  char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “eogksalsrnr”;
    char   dest[20 + 1];
    
    rc = pfmStrEngToKsc(desc, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

58. pfmStrKscToEng

Converts a KSC5601 string to English code.

  • Prototype

    long pfmStrKscToEng(unsigned char *dest, unsigned  char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “대한민국”;
    char   dest[20 + 1];
    
    rc = pfmStrKscToEng(desc, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

59. pfmStrKscToIbm

Converts a KSC5601 string to IBM 2-byte combination code.

  • Prototype

    long pfmStrKscToIbm(unsigned char *dest, unsigned  char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “대한민국”;
    char   dest[20 + 1];
    
    rc = pfmStrKscToIbm(desc, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

60. pfmStrIbmToKsc

Converts IBM 2-byte combination code to a KSC5601 string.

  • Prototype

    long pfmStrIbmToKsc(unsigned char *dest, unsigned  char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “대한민국”;
    char   dest[20 + 1];
    
    rc = pfmStrIbmToKsc(desc, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

61. pfmStrKscToSosi

Converts a KS 2-byte complete Korean string to IBM SOSI Korean code.

  • Prototype

    long pfmStrKscToSosi(char *dest, long dest_len, char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    dest_len (input)

    Length of the converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “ 오대한 민국 abc   defg”;
    char   dest[100];
    
    rc = pfmStrKscToSosi(dest, 100, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    /* Normal conversion: dest = 0x0e + “오 대한민국” + 0x0f + “ abc  defg” */

62. pfmStrSosiToKsc

Converts IBM SOSI Korean code to a KS 2-byte complete Korean string.

  • Prototype

    long pfmStrSosiToKsc(char *dest, long dest_len, char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    dest_len (input)

    Length of the converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “ 오 대한민국 abc   defg”;
    char   dest[100];
    char   dest2[100];
    
    rc = pfmStrSosiToKsc(dest, 100, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    
    rc = pfmStrSosiToKsc(dest2, 100, dest, strlen(dest));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    
    /* Normal conversion: dest = “오 대한민국 abc   defg” */

63. pfmStrKscConvEng

Converts a Korean string to an English string.

  • Prototype

    long pfmStrKscConvEng(char *dest, long dest_len, char *src, long src_len,
    long conv_flag);
  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   dest[256];
    char   *src  =  “홍길동”;
    
    rc = pfmStrKscConvEng(dest, sizeof(dest), src,
     strlen(src), PFM_KSC_CONV_ENG_DEFAULT);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    
    /* dest = KIMGILDONG : General notation */
    rc = pfmStrKscConvEng(dest, sizeof(dest), src,
     strlen(src), PFM_KSC_CONV_ENG_ROMAN);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    /* dest = GIMGILDONG : Roman notation */

64. pfmStrKscToRemoveSpace

Removes spaces from a KSC5601 Korean string.

  • Prototype

    long pfmStrKscToRemoveSpace(char *dest, long dest_len, char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    dest_len (input)

    Length of the converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “대 한 민 국”;
    char   dest[20 + 1];
    
    rc = pfmStrKscToRemoveSpace(desc, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

65. pfmStrKscToTwoBytes

Converts 1-byte characters (alphanueric characters, symbols, etc.) included in a string to KSC5601 2-byte characters. This means that half-width characters are converted to full-width characters.

  • Prototype

    long pfmStrKscToTwoBytes(char *dest, long dest_len, char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    dest_len (input)

    Length of the converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

    The address of the string to convert must be different from that of the converted string. Blanks after the conversion are padded with KSC5601 spaces (0xa1a1). If the length of the converted string is the same as that of the buffer, the string cannot be terminated with null. Therefore, set "dest_len = scr_len *2+1".

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “대 한 민 국”;
    char   dest[20 + 1];
    bzero(dest, sizeof(dest));
    rc = pfmStrKscToTwoBytes(desc, 20, src, 11);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

66. pfmStrKscToOneByte

Converts KSC5601 2-byte characters (alphanueric characters, symbols, etc.) included in a string to 1-byte characters. This means that full-width characters are converted to half-width characters.

  • Prototype

    long pfmStrKscToOneByte(char *dest, long dest_len, char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    Converted string.

    dest_len (input)

    Length of the converted string.

    *src (input)

    String to convert.

    src_len (input)

    Length of the string to convert.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “대 한 민 국”;
    char   dest[20 + 1];
    
    bzero(dest, sizeof(dest));
    rc = pfmStrKscToOneByte(desc, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

67. pfmStrnConv

Converts a string with a given conversion method.

  • Prototype

    long pfmStrnConv(char *src, long len, long type);
  • Parameters

    Parameter Description

    *src (input/output)

    String to convert.

    len (input)

    Length of the string to convert.

    type (input)

    Conversion method.

    • MPFM_STRNCONV_CNTL2SP: Converts control characters in a fixed-length string to spaces (0x20).

    • MPFM_STRNCONV_NULL2SP: Converts null characters in a fixed-length string to spaces (0x20).

    • MPFM_STRNCONV_ONLY_ALNUM_UPPER: Converts alphabet characters in a fixed-length string to uppercase.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   str[]  =  { ‘A’, ‘b’, 0x12, 0x13, ‘C’, 0x00 };
    
    rc = pfmStrnConv(str, strlen(str), MPFM_STRNCONV_CNTL2SP);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    
    /* str = {‘A’, ‘b’, 0x12, 0x13, ‘C’, 0x00 }; */
    /*-------------------------------------- */
    char   str[]  =  { ’A’, ’b’, 0x00, ’C’, 0x00, 0x00 };
    
    rc = pfmStrnConv(str, 5, MPFM_STRNCONV_NULL2SP);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    
    /* str = {‘A’, ‘b’, 0x20, ‘C’, 0x20, 0x00 }; */
    /*-------------------------------------- */
    char   str[]  =  “2005년 11월 02일 Wed”;
    rc = pfmStrnConv(str, 5, MPFM_STRNCONV_ONLY_ALNUM_UPPER);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }

68. pfmStrnCpyConv

Converts a string with a given conversion method and then copies it to another string.

  • Prototype

    long pfmStrnCpyConv(char *dest, char *src, long len, long type);
  • Parameters

    Parameter Description

    *dest (output)

    String to which the converted string is copied.

    *src (input)

    String to convert.

    len (input)

    Length of the string to convert.

    type (input)

    Conversion method.

    • MPFM_STRNCONV_CNTL2SP: Converts control characters in a fixed-length string to spaces (0x20).

    • MPFM_STRNCONV_NULL2SP: Converts null characters in a fixed-length string to spaces (0x20).

    • MPFM_STRNCONV_ONLY_ALNUM_UPPER: Converts alphabet characters in a fixed-length string to uppercase.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   str[]  =  { ‘A’, ‘b’, 0x12, 0x13, ‘C’, 0x00 };
    char   buf[10 + 1];
    
    rc = pfmStrnCopyConv(buf, str, 10, MPFM_STRNCONV_CNTL2SP);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    
    /* buf = { ‘A’, ‘b’, 0x20, 0x20, ‘C’, 0x00 }; */
    /*-------------------------------------- */
    char   str[]  =  { ’A’, ’b’, 0x00, ’C’, 0x00, 0x00 };
    char   buf[10 + 1];
    
    rc = pfmStrnConv(buf, str, 10, MPFM_STRNCONV_NULL2SP);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    
    /* str = { ‘A’, ‘b’, 0x20, ‘C’, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00 }; */
    /*-------------------------------------- */
    char   str[]  =  “2005년 11월 02일 Wed”;
    char   buf[10 + 1];
    rc = pfmStrnConv(buf, str, 10, MPFM_STRNCONV_ONLY_ALNUM_UPPER);
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    /* buf = “20051102Wed” */

69. pfmStrRemoveBrokenKorean

Removes broken Korean characters from an input string.

  • Prototype

    long pfmStrRemoveBrokenKorean(char *dest, long dest_len, char *src, long src_len);
  • Parameters

    Parameter Description

    *dest (output)

    String without broken Korean characters.

    dest_len (input)

    Length of the string without broken Korean characters.

    *src (input)

    Input string.

    src_len (input)

    Length of the input string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed succesffully.

  • Example

    char   src[]  =  “중간에ㄺ 깨짐”;
    char   buf[20 + 1];
    
    rc = pfmStrRemoveBrokenKorean(buf, 20, src, strlen(src));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
       return RC_ERR;
    }
    PFM_ERR("[%s]", buf );
    /* buf = “중간에   깨짐”*/

70. pfmStrIndexOfBrokenKorean

Gets the location of the first broken Korean character in an input string.

  • Prototype

    long pfmStrIndexOfBrokenKorean(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    Null-terminated string.

    len (input)

    Length of the null-terminated string.

  • Return values

    Returns the location of the first broken Korean character in an input string.

  • Example

    char   str[100 + 1]  =  “KOREA에오신걸ㄺ환영합니다”;
    long   broken_pos;
    
    broken_pos = pfmStrIndexOfBrokenKorean(str, strlen(str));
    /* broken_pos = 13 */

71. pfmStrRemoveBrokenKsc

Removes broken characters from an input string and displays full-width Korean characters. It complements pfmStrRemoveBrokenKorean.

  • Prototype

    long pfmStrRemoveBrokenKsc(char *dest, long dest_len, char *src, long src_len, long del_byte, char *option)
  • Parameters

    Parameter Description

    *dest (output)

    Output string.

    dest_len (output)

    Length of the output string.

    *src (input)

    Input string.

    src_len (input)

    Length of the input string.

    del_byte (input)

    Unit to remove. Either 1 byte or 2 bytes. If this is 1 byte, removed characters are treated as 0x20. It this is 2 bytes, they are treated as 0xA1.

    option (input)

    Allowed characters. One of the following characters:

    • K: Korean syllables

    • k: Korean characters

    • A: Full-width uppercase

    • a: Full-width lowercase

    • N: Full-width numbers

    • C: Full-width ASCII

    • G: Graphic characters

  • Return values

    Returns the location of the first broken Korean character in an input string.

  • Example

    {
     char src[256];
     char dst[256];
     char opt[256];
     STRCPY(src, "가나,ㄱㄴㅏㅑ,ABYZ,abyz,0189,!"} ̄, 、。,℡ " );
     PFM_ERR("src=[%d:%s]", strlen(src), src);
    
     /* Unit to remove: 1 byte, the default option */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 1, NULL ) );
     PFM_ERR("dst=[%d:%s]", strlen(dst), dst);
     /*dst=[60:가나,     엘 ,ABYZ,abyz,0189,!"} ̄,     ,   ]
       "엘" is the value between "ㄱㄴ" (1st and 2nd array values) because the unit to remove is 1 byte. */
    
     /* Unit to remove: 2 bytes */
     /* NULL = DEFAULT = "KC" option */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, NULL ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "NULL" );
     /*dst=[60:가나,    ,ABYZ,abyz,0189,!"} ̄,   ,  ], opt=NULL*/
    
     /* EMPTY STRING = DEFAULT = "KC" option */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "" );
     /*dst=[60:가나,    ,ABYZ,abyz,0189,!"} ̄,   ,  ], opt=*/
    
     /* "K": Only Korean syllables are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "K" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "K" );
     /*dst=[60:가나,    ,    ,    ,    ,    ,   ,  ], opt=K*/
    
     /* "k": Only Korean characters are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "k" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "k" );
     /*dst=[60:  ,ㄱㄴㅏㅑ,    ,    ,    ,    ,   ,  ], opt=k*/
    
     /* Only full-width uppercases are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "A" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "A" );
     /*dst=[60:  ,    ,ABYZ,    ,    ,    ,   ,  ], opt=A*/
    
     /* Only full-width lowercases are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "a" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "a" );
     /*dst=[60:  ,    ,    ,abyz,    ,    ,   ,  ], opt=a*/
    
     /* Only full-width numbers are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "N" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "N" );
     /*dst=[60:  ,    ,    ,    ,0189,    ,   ,  ], opt=N*/
    
     /* Only full-width characters corresponding ASCII characters are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "C" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "C" );
     /*dst=[60:  ,    ,ABYZ,abyz,0189,!"} ̄,   ,  ], opt=C*/
    
     /* Only graphic characters are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "G" ) );
     PFM_ERR("dst=[%d:%s], opt=%s", strlen(dst), dst, "G" );
     /*dst=[60:  ,    ,    ,    ,    ,    , 、。,℡ ], opt=G*/
    
     /* Lorean syllables, graphic characters, and numbers are allowed. */
     PFM_TRY( pfmStrRemoveBrokenKsc( dst, sizeof(dst)-1, src, strlen(src), 2, "KGN" ) );
     PFM_ERR("dst=[%d:%s], opt=%-10s", strlen(dst), dst, "KGN" );
     /*dst=[60:가나,    ,ABYZ,abyz,0189,    ,   ,  ], opt=KGN*/
    }

72. pfmStrTrimKscN

Removes blank or KSC5601 spaces before or after a string.

  • Prototype

    char * pfmStrTrimKscN(char *str, long len);
  • Parameters

    Parameter Description

    *str (input)

    Null-terminated string.

    len (input)

    Length of the null-terminated string.

  • Return values

    Returns a string after removing blank or KSC5601 spaces before or after the string.

  • Example

    char   str[100 + 1]  =  “     Welcome to KOREA          ”;
    pfmStrTrimKscN(str, strlen(str));
    /* str = “Welcome to KOREA” */

73. pfmStrGetErrorMsg

Returns an error message when a String utility error occurs.

  • Prototype

    char * pfmStrGetErrorMsg(void);
  • Return values

    Returns the error message.

  • Example

    rc = pfmStrSosiToKsc(dest2, 100, dest, strlen(dest));
    if(rc != RC_NRM) {
       PFM_ERR(“%s”, pfmStrGetErrorMsg());
    /* Or, PFM_ERR(“%s”, pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }