(FEA) Featured for Location_Literalisation, Status_Literalisation etc.
This commit is contained in:
@@ -22,7 +22,6 @@ Status String_Delete(String *inst);
|
||||
Status String_GetIdx(String *inst, Char *item, int index);
|
||||
Status String_SetIdx(String *inst, Char *item, int index);
|
||||
Status String_Literalise(String *inst, String *store);
|
||||
bool String_Equals(String *arr1, String *arr2);
|
||||
|
||||
/* Extensional. */
|
||||
Status StringUtils_FromInteger(String *inst, int value);
|
||||
@@ -83,6 +82,7 @@ Status String_Decode(String *inst, StringEncoding encoding);
|
||||
int StringUtils_Compare(String *a, String *b);
|
||||
|
||||
static Status StringConversionPrecisionError = {
|
||||
.value = 1,
|
||||
.description = "Unpreventable precision loss was found during conversion "
|
||||
"between string and raw data.",
|
||||
.characteristic = STATUS_ERROR,
|
||||
|
@@ -2,14 +2,9 @@
|
||||
|
||||
Status String_Create(String *inst, int len)
|
||||
{
|
||||
Status create = Array_Create(inst, len);
|
||||
solve(!(StatusUtils_IsOkay(create)), {
|
||||
Report e = stamp(error(create, "Failed to create a string."),
|
||||
nameof(Array_Create));
|
||||
(void)_throw(e);
|
||||
return ReportThrown;
|
||||
})
|
||||
|
||||
/* Create an array has length len + 1, for termination character in string. */
|
||||
ensure(Array_Create(inst, len + 1, sizeof(int)), "Failed to create a string.");
|
||||
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
@@ -23,12 +18,12 @@ Status String_Delete(String *inst)
|
||||
fails(inst, UnavailableInstance);
|
||||
}
|
||||
|
||||
Status String_GetIdx(String *inst, Char *store, int index)
|
||||
Status String_GetAt(String *inst, Char *store, int index)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
}
|
||||
|
||||
Status String_SetIdx(String *inst, Char *source, int index)
|
||||
Status String_SetAt(String *inst, Char *source, int index)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
}
|
||||
@@ -38,8 +33,30 @@ Status String_Literalise(String *inst, String *store)
|
||||
fails(inst, UnavailableInstance);
|
||||
}
|
||||
|
||||
bool String_Equals(String *arr1, String *arr2)
|
||||
int StringUtils_Compare(String *a, String *b)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
}
|
||||
/* Both being null is counted as equal. */
|
||||
state(a == NULL && b == NULL, 0);
|
||||
|
||||
/* Compare by iterating through each element to calculate differing
|
||||
values between a[i] and b[i]. */
|
||||
const int len = max(a->len, b->len);
|
||||
for (register int i = 0; i < len; i++) {
|
||||
const int comp =
|
||||
(*(char *)(a->members[i].addr) - *(char *)(b->members[i].addr));
|
||||
|
||||
/*
|
||||
If values from both side does not equal, return the differential value.
|
||||
*/
|
||||
if (!comp) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
/* Even the previous elements are same, but the length must be compared
|
||||
because we haven't really done this.
|
||||
The reason that we don't compare it earlier is though we can know whether
|
||||
the lengths are the same or not, we, however, cannot give a precise value
|
||||
telling which content from string is "greater" or "less". */
|
||||
return (a->len != b->len);
|
||||
}
|
||||
|
Reference in New Issue
Block a user