String functions

String functions — Helper functions for conversions to and from different types of strings.

Synopsis


#include <jclass/jstring.h>


char*       jclass_utf8_to_string           (const uint8_t *utf8_string,
                                             uint16_t length);
char*       jclass_get_printable_string     (const char *raw_string);
char*       jclass_float_to_string          (uint32_t float_bytes);
char*       jclass_double_to_string         (uint64_t double_bytes);
char*       jclass_descriptor_get_type      (const char *descriptor);
char*       jclass_descriptor_get_parameters
                                            (const char *descriptor);
char**      jclass_descriptor_get_parameters_array
                                            (const char *descriptor);
char*       jclass_access_flag_to_string    (uint16_t access_flag,
                                             int is_class);
char*       jclass_get_package_from_class_name
                                            (const char *class_name);
char*       jclass_get_class_from_method_signature
                                            (const char *method_signature);
char*       jclass_classname_to_filename    (const char *class_name,
                                             char path_slash);
int         jclass_string_is_primitive_type (const char *type_string);

Description

Details

jclass_utf8_to_string ()

char*       jclass_utf8_to_string           (const uint8_t *utf8_string,
                                             uint16_t length);

Converts a java UTF-8 string to its ASCII equivalent. Java uses a slightly different format than standard UTF-8.

utf8_string : A pointer to the UTF-8 string.
length : The length of the string in bytes.
Returns : A string allocated with malloc.

jclass_get_printable_string ()

char*       jclass_get_printable_string     (const char *raw_string);

Translates a string to a more human readable form. All control characters are converted to escape characters.

raw_string : The string to translate (it is not changed).
Returns : A string allocated with malloc.

jclass_float_to_string ()

char*       jclass_float_to_string          (uint32_t float_bytes);

Gives a string representation of a float.

float_bytes : The float contained in a uint32 integer.
Returns : A string allocated with malloc.

jclass_double_to_string ()

char*       jclass_double_to_string         (uint64_t double_bytes);

Converts a double to a string.

double_bytes : The double contained in a uint64.
Returns : A string allocated with malloc.

jclass_descriptor_get_type ()

char*       jclass_descriptor_get_type      (const char *descriptor);

Gives the type of a coded descriptor.

descriptor : The coded descriptor string.
Returns : A string allocated with malloc containg the type in the descriptor.

jclass_descriptor_get_parameters ()

char*       jclass_descriptor_get_parameters
                                            (const char *descriptor);

Deprecated. Use jclass_descriptor_get_parameters_array() instead. Gives the parameters part of a coded descriptor.

descriptor : The coded descriptor.
Returns : A string allocated with malloc containg the parameters in the descriptor.

jclass_descriptor_get_parameters_array ()

char**      jclass_descriptor_get_parameters_array
                                            (const char *descriptor);

Gives the parameters part of a coded descriptor.

descriptor : The coded descriptor.
Returns : A NULL terminated string array allocated with malloc containg the parameters in the descriptor.

jclass_access_flag_to_string ()

char*       jclass_access_flag_to_string    (uint16_t access_flag,
                                             int is_class);

Gives the string representation of an access flag.

access_flag : The access flag.
is_class : Set to 1 if the flags are for a class, 0 otherwise.
Returns : A string allocated with malloc.

jclass_get_package_from_class_name ()

char*       jclass_get_package_from_class_name
                                            (const char *class_name);

Given a full class name it returns the package the class is a member of. If the class is not part of a package it returns NULL.

class_name : The fully qualified class name.
Returns : A string allocated with malloc.

jclass_get_class_from_method_signature ()

char*       jclass_get_class_from_method_signature
                                            (const char *method_signature);

Gives the name of the class given a method signature for one of its methods.

method_signature : The method signature.
Returns : A string allocated with malloc.

jclass_classname_to_filename ()

char*       jclass_classname_to_filename    (const char *class_name,
                                             char path_slash);

Converts the given class name to a filename. For example java.lang.String will be converted to: java/lang/String.class.

class_name : The name of the class.
path_slash : The slash for your OS ('/' for Unices, '\\' for Win).
Returns : A string allocated with malloc with the filename.

jclass_string_is_primitive_type ()

int         jclass_string_is_primitive_type (const char *type_string);

Checks whether the given string is the name of a primitive type.

type_string : A null terminated string.
Returns : 1 if the type given is a pritive type, 0 otherwise.