object: unify stringstream functionality
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "uuid.h"
|
||||
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/object/type.h>
|
||||
#include <blue/object/uuid.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <ctype.h>
|
||||
#include "uuid.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static struct b_object_type uuid_type = {
|
||||
.t_name = "corelib::uuid",
|
||||
@@ -16,7 +18,8 @@ static struct b_object_type uuid_type = {
|
||||
|
||||
struct b_uuid *b_uuid_create(void)
|
||||
{
|
||||
struct b_uuid *out = (struct b_uuid *)b_object_type_instantiate(&uuid_type);
|
||||
struct b_uuid *out
|
||||
= (struct b_uuid *)b_object_type_instantiate(&uuid_type);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -25,9 +28,10 @@ struct b_uuid *b_uuid_create(void)
|
||||
}
|
||||
|
||||
struct b_uuid *b_uuid_create_from_bytes(
|
||||
unsigned char u00, unsigned char u01, unsigned char u02, unsigned char u03,
|
||||
unsigned char u04, unsigned char u05, unsigned char u06, unsigned char u07,
|
||||
unsigned char u08, unsigned char u09, unsigned char u10, unsigned char u11,
|
||||
unsigned char u00, unsigned char u01, unsigned char u02,
|
||||
unsigned char u03, unsigned char u04, unsigned char u05,
|
||||
unsigned char u06, unsigned char u07, unsigned char u08,
|
||||
unsigned char u09, unsigned char u10, unsigned char u11,
|
||||
unsigned char u12, unsigned char u13, unsigned char u14, unsigned char u15)
|
||||
{
|
||||
struct b_uuid *uuid = b_uuid_create();
|
||||
@@ -35,16 +39,16 @@ struct b_uuid *b_uuid_create_from_bytes(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uuid->uuid_bytes.uuid_bytes[ 0] = u00;
|
||||
uuid->uuid_bytes.uuid_bytes[ 1] = u01;
|
||||
uuid->uuid_bytes.uuid_bytes[ 2] = u02;
|
||||
uuid->uuid_bytes.uuid_bytes[ 3] = u03;
|
||||
uuid->uuid_bytes.uuid_bytes[ 4] = u04;
|
||||
uuid->uuid_bytes.uuid_bytes[ 5] = u05;
|
||||
uuid->uuid_bytes.uuid_bytes[ 6] = u06;
|
||||
uuid->uuid_bytes.uuid_bytes[ 7] = u07;
|
||||
uuid->uuid_bytes.uuid_bytes[ 8] = u08;
|
||||
uuid->uuid_bytes.uuid_bytes[ 9] = u09;
|
||||
uuid->uuid_bytes.uuid_bytes[0] = u00;
|
||||
uuid->uuid_bytes.uuid_bytes[1] = u01;
|
||||
uuid->uuid_bytes.uuid_bytes[2] = u02;
|
||||
uuid->uuid_bytes.uuid_bytes[3] = u03;
|
||||
uuid->uuid_bytes.uuid_bytes[4] = u04;
|
||||
uuid->uuid_bytes.uuid_bytes[5] = u05;
|
||||
uuid->uuid_bytes.uuid_bytes[6] = u06;
|
||||
uuid->uuid_bytes.uuid_bytes[7] = u07;
|
||||
uuid->uuid_bytes.uuid_bytes[8] = u08;
|
||||
uuid->uuid_bytes.uuid_bytes[9] = u09;
|
||||
uuid->uuid_bytes.uuid_bytes[10] = u10;
|
||||
uuid->uuid_bytes.uuid_bytes[11] = u11;
|
||||
uuid->uuid_bytes.uuid_bytes[12] = u12;
|
||||
@@ -148,20 +152,27 @@ b_status b_uuid_to_string(const struct b_uuid *uuid, struct b_string *out)
|
||||
|
||||
b_status b_uuid_to_cstr(const struct b_uuid *uuid, char out[B_UUID_STRING_MAX])
|
||||
{
|
||||
snprintf(out, B_UUID_STRING_MAX,
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
uuid->uuid_bytes.uuid_bytes[ 0], uuid->uuid_bytes.uuid_bytes[ 1], uuid->uuid_bytes.uuid_bytes[ 2], uuid->uuid_bytes.uuid_bytes[ 3],
|
||||
uuid->uuid_bytes.uuid_bytes[ 4], uuid->uuid_bytes.uuid_bytes[ 5], uuid->uuid_bytes.uuid_bytes[ 6], uuid->uuid_bytes.uuid_bytes[ 7],
|
||||
uuid->uuid_bytes.uuid_bytes[ 8], uuid->uuid_bytes.uuid_bytes[ 9], uuid->uuid_bytes.uuid_bytes[10], uuid->uuid_bytes.uuid_bytes[11],
|
||||
uuid->uuid_bytes.uuid_bytes[12], uuid->uuid_bytes.uuid_bytes[13], uuid->uuid_bytes.uuid_bytes[14], uuid->uuid_bytes.uuid_bytes[15]);
|
||||
snprintf(
|
||||
out, B_UUID_STRING_MAX,
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%"
|
||||
"02x%02x",
|
||||
uuid->uuid_bytes.uuid_bytes[0], uuid->uuid_bytes.uuid_bytes[1],
|
||||
uuid->uuid_bytes.uuid_bytes[2], uuid->uuid_bytes.uuid_bytes[3],
|
||||
uuid->uuid_bytes.uuid_bytes[4], uuid->uuid_bytes.uuid_bytes[5],
|
||||
uuid->uuid_bytes.uuid_bytes[6], uuid->uuid_bytes.uuid_bytes[7],
|
||||
uuid->uuid_bytes.uuid_bytes[8], uuid->uuid_bytes.uuid_bytes[9],
|
||||
uuid->uuid_bytes.uuid_bytes[10], uuid->uuid_bytes.uuid_bytes[11],
|
||||
uuid->uuid_bytes.uuid_bytes[12], uuid->uuid_bytes.uuid_bytes[13],
|
||||
uuid->uuid_bytes.uuid_bytes[14], uuid->uuid_bytes.uuid_bytes[15]);
|
||||
return B_SUCCESS;
|
||||
}
|
||||
|
||||
b_status b_uuid_to_strv_builder(const struct b_uuid *uuid, struct b_strv_builder *out)
|
||||
b_status b_uuid_to_stringstream(
|
||||
const struct b_uuid *uuid, struct b_stringstream *out)
|
||||
{
|
||||
char str[B_UUID_STRING_MAX];
|
||||
b_uuid_to_cstr(uuid, str);
|
||||
b_strv_builder_add(out, str);
|
||||
b_stringstream_add(out, str);
|
||||
|
||||
return B_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user