summaryrefslogtreecommitdiff
path: root/innobase/ut/ut0byte.c
blob: 8764103dc367dae4a7675cfb412025fe18d5db08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************
Byte utilities

(c) 1994, 1995 Innobase Oy

Created 5/11/1994 Heikki Tuuri
********************************************************************/

#include "ut0byte.h"

#ifdef UNIV_NONINL
#include "ut0byte.ic"
#endif

#include "ut0sort.h"

/* Zero value for a dulint */
dulint	ut_dulint_zero 		= {0, 0};

/* Maximum value for a dulint */
dulint	ut_dulint_max 		= {0xFFFFFFFFUL, 0xFFFFFFFFUL};

/****************************************************************
Sort function for dulint arrays. */
void
ut_dulint_sort(dulint* arr, dulint* aux_arr, ulint low, ulint high)
/*===============================================================*/
{
	UT_SORT_FUNCTION_BODY(ut_dulint_sort, arr, aux_arr, low, high,
				ut_dulint_cmp);
}

/****************************************************************
Copies a string to a memory location, setting characters to lower case. */

void
ut_cpy_in_lower_case(
/*=================*/
	char*		dest,	/* in: destination */
	const char*	source,	/* in: source */
	ulint		len)	/* in: string length */
{
        ulint i;

	for (i = 0; i < len; i++) {
	        dest[i] = tolower(source[i]);
	}
}

/****************************************************************
Compares two strings when converted to lower case. */

int
ut_cmp_in_lower_case(
/*=================*/
				/* out: -1, 0, 1 if str1 < str2, str1 == str2,
				str1 > str2, respectively */
	const char*	str1,	/* in: string1 */
	const char*	str2)	/* in: string2 */
{
	for (;;) {
		int c1, c2;
		if (!*str1) {
			return(*str2 ? -1 : 0);
		} else if (!*str2) {
			return 1;
		}
		c1 = tolower(*str1++);
		c2 = tolower(*str2++);
		if (c1 < c2) {
			return(-1);
		}
		if (c1 > c2) {
			return(1);
		}
	}

	return(0);
}