Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_function_hexBinary.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * afw_function_execute_* functions for hexBinary
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 
18 /*
19  * Adaptive function: decode_to_string<hexBinary>
20  *
21  * afw_function_execute_decode_to_string_hexBinary
22  *
23  * See afw_function_bindings.h for more information.
24  *
25  * Decode hexBinary value to string. An error is thrown if decoded value is not
26  * valid UTF-8.
27  *
28  * This function is pure, so it will always return the same result
29  * given exactly the same parameters and has no side effects.
30  *
31  * Declaration:
32  *
33  * ```
34  * function decode_to_string<hexBinary>(
35  * value: hexBinary
36  * ): string;
37  * ```
38  *
39  * Parameters:
40  *
41  * value - (hexBinary) The hexBinary value to decode.
42  *
43  * Returns:
44  *
45  * (string) The decoded string.
46  */
47 const afw_value_t *
50 {
51  afw_value_string_t *result;
52  const afw_value_hexBinary_t *value;
53 
55 
56  result = afw_value_allocate_string(x->p, x->xctx);
57  result->internal.s = (const afw_utf8_octet_t *)value->internal.ptr;
58  result->internal.len = value->internal.size;
59 
60  if (!afw_utf8_is_valid(result->internal.s, result->internal.len, x->xctx))
61  {
62  AFW_THROW_ERROR_Z(general, "value does not decode to valid utf-8",
63  x->xctx);
64  }
65 
66  return (const afw_value_t *)result;
67 }
Adaptive Framework Core Internal.
afw_value_allocate_string(const afw_pool_t *p, afw_xctx_t *xctx)
Allocate function for unmanaged data type string value.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
Definition: afw_common.h:236
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
#define AFW_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE)
Evaluate an arg for a particular data type.
Definition: afw_function.h:328
const afw_value_t * afw_function_execute_decode_to_string_hexBinary(afw_function_execute_t *x)
Adaptive Function decode_to_string<hexBinary>
#define afw_utf8_is_valid(s, len, xctx)
Determine if series of bytes is valid utf-8.
Definition: afw_utf8.h:154
Function execute parameter.
Definition: afw_function.h:53
afw_xctx_t * xctx
The execution context (xctx) of caller.
Definition: afw_function.h:62
const afw_pool_t * p
Pool for result.
Definition: afw_function.h:59
struct for data type hexBinary values.
Interface afw_value public struct.
struct for data type string values.