summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format/constants.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-05-18 21:50:26 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-05-18 21:50:26 (GMT)
commit041056d04032d41a5c092c62cbfd67b199094991 (patch)
treea294afa55e307fe68617f80af3e9999ad7fa28b6 /plugins/pychrysalide/format/constants.c
parent4f18f051936f633473c365d4c91ef7e77fa7feee (diff)
Updated the Python API for string symbols.
Diffstat (limited to 'plugins/pychrysalide/format/constants.c')
-rw-r--r--plugins/pychrysalide/format/constants.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/plugins/pychrysalide/format/constants.c b/plugins/pychrysalide/format/constants.c
index 0df7bd4..9669b46 100644
--- a/plugins/pychrysalide/format/constants.c
+++ b/plugins/pychrysalide/format/constants.c
@@ -26,6 +26,7 @@
#include <format/format.h>
+#include <format/strsym.h>
#include <format/symbol.h>
@@ -159,3 +160,102 @@ bool define_binary_symbol_constants(PyTypeObject *type)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type dont le dictionnaire est à compléter. *
+* *
+* Description : Définit les constantes pour les symboles liés à des chaînes. *
+* *
+* Retour : true en cas de succès de l'opération, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_string_symbol_constants(PyTypeObject *type)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *values; /* Groupe de valeurs à établir */
+
+ result = true;
+
+ values = PyDict_New();
+
+ if (result) result = add_const_to_group(values, "NONE", SET_NONE);
+ if (result) result = add_const_to_group(values, "ASCII", SET_ASCII);
+ if (result) result = add_const_to_group(values, "UTF_8", SET_UTF_8);
+ if (result) result = add_const_to_group(values, "MUTF_8", SET_MUTF_8);
+ if (result) result = add_const_to_group(values, "GUESS", SET_GUESS);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, false, "StringEncodingType", values,
+ "Kinds of encoding for strings.");
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en constante StringEncodingType. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_string_encoding_type(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+ unsigned long value; /* Valeur transcrite */
+
+ result = PyObject_IsInstance(arg, (PyObject *)&PyLong_Type);
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to StringEncodingType");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if (value > SET_GUESS)
+ {
+ PyErr_SetString(PyExc_TypeError, "invalid value for StringEncodingType");
+ result = 0;
+ }
+
+ else
+ *((StringEncodingType *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}