NewStrings

 

Derived from: none

Declared in: NewStrings.h

Library: none


Overview

Provides a version of strdup() which returns the duplicate string in memory that has been allocated using new char[] instead of malloc(), so that it can be freed using delete[] instead of free(). Also provides a version of strcat() which returns the concatenated string in memory allocated using new char[], as well as similar functions which concatenate more than two strings. There are other handy string manipulation functions in NewStrings.h as well (see below).


Utility functions

 


GetStringsMaxWidth()

 
      float GetStringsMaxWidth(const char** strings, int32 num_strings, const BFont* font,
            float* string_widths = NULL)

 

Returns the pixel width of the longest string in the strings array in the font specified. If a string_widths array is provided, then the widths of the individual strings are filled into that array.


StringBoundingBox(), GetStringsBoundingBoxes()

 
      BRect StringBoundingBox(const char* string, const BFont* font, bool full_height = false,
            bool round_up = true)
      BRect GetMaxStringBoundingBoxes(const char** strings, int32 num_strings, const BFont* font,
            BRect* rects = NULL, bool full_height = false, bool round_up = true)

 

Gets the bounding box for one or more strings. If full_height is true, it increases the top and bottom to the font's ascent and descent. If round_up is true, it rounds each edge up to the next pixel to get a box that will actually be occupied onscreen. In GetMaxStringBoundingBoxes(), if rects is not null, then the individual bounding boxes are filled into that array.


Strcat_new()

 
char *Strcat_new(const char *string_1, const char *string_2)
char *Strcat_new(const char *string_1, const char *string_2, const char *string_3)
char *Strcat_new(const char *string_1, const char *string_2, const char *string_3, const char *string_4)

 

A version of strcat() which returns the concatenated string in memory allocated using new char[], as well as similar functions which concatenate more than two strings.


Strdup_new()

 
      char *Strdup_new(const char *source)

 

A version of strdup() which returns the duplicate string in memory that has been allocated using new char[] instead of malloc(), so that it can be freed using delete[] instead of free().


Strtcpy()

 
      char *Strtcpy(char *dst, const char *src, int len)

 

Provided because due to some error, the Be libraries on x86 don't export strtcopy(). Len includes the null terminator.


StrToUpper(), StrToLower()

 
      void StrToUpper(char* string)
      void StrToLower(char* string)
 

Converts a string to upper or lower case, respectively.


By Brian Tietz

Copyright 2000

Bug reports (including documentation errors) and feature requests can be sent to briant@timelinevista.com.