Prefix the JNI types from SquirrelJME with sjme_ so that they can easily be mixed...
[SquirrelJME.git] / nanocoat / src / util.c
blob6553e71b56d9d7f474c348925197e273a22eb14b
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include "sjme/nvm.h"
11 #include "sjme/util.h"
12 #include "sjme/debug.h"
14 sjme_jchar sjme_decodeUtfChar(const char* at, const char** stringP)
16 if (at == NULL)
17 return -1;
19 sjme_todo("sjme_decodeUtfChar()");
20 return -1;
23 /**
24 * Initializes the random number generator.
26 * @param outRandom The random state to initialize.
27 * @param seedHi The high seed value.
28 * @param seedLo The low seed value.
29 * @return Returns @c SJME_JNI_TRUE on success.
30 * @since 2023/12/02
32 sjme_jboolean sjme_randomInit(
33 sjme_attrInOutNotNull sjme_random* outRandom,
34 sjme_attrInValue sjme_jint seedHi,
35 sjme_attrInValue sjme_jint seedLo)
37 sjme_todo("Implement this?");
38 return SJME_JNI_FALSE;
41 sjme_jboolean sjme_randomInitL(
42 sjme_attrInOutNotNull sjme_random* outRandom,
43 sjme_attrInValue sjme_jlong seed)
45 sjme_todo("Implement this?");
46 return SJME_JNI_FALSE;
49 sjme_jboolean sjme_randomNextInt(
50 sjme_attrInOutNotNull sjme_random* random,
51 sjme_attrOutNotNull sjme_jint* outValue)
53 sjme_todo("Implement this?");
54 return SJME_JNI_FALSE;
57 sjme_jboolean sjme_randomNextIntMax(
58 sjme_attrInOutNotNull sjme_random* random,
59 sjme_attrOutNotNull sjme_jint* outValue,
60 sjme_attrInPositiveNonZero sjme_jint maxValue)
62 sjme_todo("Implement this?");
63 return SJME_JNI_FALSE;
66 sjme_jint sjme_stringHash(const char* string)
68 sjme_jint result;
69 sjme_jchar c;
70 const char* p;
72 if (string == NULL)
73 return 0;
75 /* Initial result. */
76 result = 0;
78 /* Read until end of string. */
79 for (p = string; *p != 0;)
81 /* Decode character. */
82 c = sjme_decodeUtfChar(p, &p);
84 /* Calculate the hashCode(), the JavaDoc gives the following formula:
85 // == s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] .... yikes! */
86 result = ((result << 5) - result) + (sjme_jint)c;
89 /* Return calculated result. */
90 return result;
93 sjme_jint sjme_stringLength(const char* string)
95 if (string == NULL)
96 return -1;
98 sjme_todo("sjme_stringLength()");
99 return -1;
102 sjme_jint sjme_treeFind(void* in, void* what,
103 const sjme_treeFindFunc* functions)
105 if (in == NULL || functions == NULL)
106 return -1;
108 sjme_todo("sjme_treeFind()");
109 return -1;