Home | History | Annotate | Download | only in Common
      1 /** @file
      2 String routines implementation
      3 
      4 Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
      5 This program and the accompanying materials
      6 are licensed and made available under the terms and conditions of the BSD License
      7 which accompanies this distribution.  The full text of the license may be found at
      8 http://opensource.org/licenses/bsd-license.php
      9 
     10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #ifndef _EFI_STRING_FUNCS_H
     16 #define _EFI_STRING_FUNCS_H
     17 
     18 #include <stdio.h>
     19 #include <stdlib.h>
     20 #include <Common/UefiBaseTypes.h>
     21 
     22 //
     23 // Common data structures
     24 //
     25 typedef struct {
     26   UINTN      Count;
     27   //
     28   // Actually this array can be 0 or more items (based on Count)
     29   //
     30   CHAR8*     Strings[1];
     31 } STRING_LIST;
     32 
     33 
     34 //
     35 // Functions declarations
     36 //
     37 
     38 CHAR8*
     39 CloneString (
     40   IN CHAR8       *String
     41   )
     42 ;
     43 /**
     44 
     45 Routine Description:
     46 
     47   Allocates a new string and copies 'String' to clone it
     48 
     49 Arguments:
     50 
     51   String          The string to clone
     52 
     53 Returns:
     54 
     55   CHAR8* - NULL if there are not enough resources
     56 
     57 **/
     58 
     59 
     60 EFI_STATUS
     61 StripInfDscStringInPlace (
     62   IN CHAR8       *String
     63   )
     64 ;
     65 /**
     66 
     67 Routine Description:
     68 
     69   Remove all comments, leading and trailing whitespace from the string.
     70 
     71 Arguments:
     72 
     73   Strin          The string to 'strip'
     74 
     75 Returns:
     76 
     77   EFI_STATUS
     78 
     79 **/
     80 
     81 
     82 STRING_LIST*
     83 SplitStringByWhitespace (
     84   IN CHAR8       *String
     85   )
     86 ;
     87 /**
     88 
     89 Routine Description:
     90 
     91   Creates and returns a 'split' STRING_LIST by splitting the string
     92   on whitespace boundaries.
     93 
     94 Arguments:
     95 
     96   String          The string to 'split'
     97 
     98 Returns:
     99 
    100   EFI_STATUS
    101 
    102 **/
    103 
    104 
    105 STRING_LIST*
    106 NewStringList (
    107   )
    108 ;
    109 /**
    110 
    111 Routine Description:
    112 
    113   Creates a new STRING_LIST with 0 strings.
    114 
    115 Returns:
    116 
    117   STRING_LIST* - Null if there is not enough resources to create the object.
    118 
    119 **/
    120 
    121 
    122 EFI_STATUS
    123 AppendCopyOfStringToList (
    124   IN OUT STRING_LIST **StringList,
    125   IN CHAR8       *String
    126   )
    127 ;
    128 /**
    129 
    130 Routine Description:
    131 
    132   Adds String to StringList.  A new copy of String is made before it is
    133   added to StringList.
    134 
    135 Returns:
    136 
    137   EFI_STATUS
    138 
    139 **/
    140 
    141 
    142 EFI_STATUS
    143 RemoveLastStringFromList (
    144   IN STRING_LIST       *StringList
    145   )
    146 ;
    147 /**
    148 
    149 Routine Description:
    150 
    151   Removes the last string from StringList and frees the memory associated
    152   with it.
    153 
    154 Arguments:
    155 
    156   StringList        The string list to remove the string from
    157 
    158 Returns:
    159 
    160   EFI_STATUS
    161 
    162 **/
    163 
    164 
    165 STRING_LIST*
    166 AllocateStringListStruct (
    167   IN UINTN StringCount
    168   )
    169 ;
    170 /**
    171 
    172 Routine Description:
    173 
    174   Allocates a STRING_LIST structure that can store StringCount strings.
    175 
    176 Arguments:
    177 
    178   StringCount        The number of strings that need to be stored
    179 
    180 Returns:
    181 
    182   EFI_STATUS
    183 
    184 **/
    185 
    186 
    187 VOID
    188 FreeStringList (
    189   IN STRING_LIST       *StringList
    190   )
    191 ;
    192 /**
    193 
    194 Routine Description:
    195 
    196   Frees all memory associated with StringList.
    197 
    198 Arguments:
    199 
    200   StringList        The string list to free
    201 
    202 Returns:
    203 
    204   EFI_STATUS
    205 
    206 **/
    207 
    208 
    209 CHAR8*
    210 StringListToString (
    211   IN STRING_LIST       *StringList
    212   )
    213 ;
    214 /**
    215 
    216 Routine Description:
    217 
    218   Generates a string that represents the STRING_LIST
    219 
    220 Arguments:
    221 
    222   StringList        The string list to convert to a string
    223 
    224 Returns:
    225 
    226   CHAR8* - The string list represented with a single string.  The returned
    227            string must be freed by the caller.
    228 
    229 **/
    230 
    231 
    232 VOID
    233 PrintStringList (
    234   IN STRING_LIST       *StringList
    235   )
    236 ;
    237 /**
    238 
    239 Routine Description:
    240 
    241   Prints out the string list
    242 
    243 Arguments:
    244 
    245   StringList        The string list to print
    246 
    247 **/
    248 
    249 
    250 #endif
    251