drivers/tty/vt/ucs.c

Source file repositories/reference/linux-study-clean/drivers/tty/vt/ucs.c

File Facts

System
Linux kernel
Corpus path
drivers/tty/vt/ucs.c
Extension
.c
Size
6316 bytes
Lines
252
Domain
Driver Families
Bucket
drivers/tty
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ucs_interval16 {
	u16 first;
	u16 last;
};

struct ucs_interval32 {
	u32 first;
	u32 last;
};

#include "ucs_width_table.h"

static int interval16_cmp(const void *key, const void *element)
{
	u16 cp = *(u16 *)key;
	const struct ucs_interval16 *entry = element;

	if (cp < entry->first)
		return -1;
	if (cp > entry->last)
		return 1;
	return 0;
}

static int interval32_cmp(const void *key, const void *element)
{
	u32 cp = *(u32 *)key;
	const struct ucs_interval32 *entry = element;

	if (cp < entry->first)
		return -1;
	if (cp > entry->last)
		return 1;
	return 0;
}

static bool cp_in_range16(u16 cp, const struct ucs_interval16 *ranges, size_t size)
{
	if (cp < ranges[0].first || cp > ranges[size - 1].last)
		return false;

	return __inline_bsearch(&cp, ranges, size, sizeof(*ranges),
				interval16_cmp) != NULL;
}

static bool cp_in_range32(u32 cp, const struct ucs_interval32 *ranges, size_t size)
{
	if (cp < ranges[0].first || cp > ranges[size - 1].last)
		return false;

	return __inline_bsearch(&cp, ranges, size, sizeof(*ranges),
				interval32_cmp) != NULL;
}

#define UCS_IS_BMP(cp)	((cp) <= 0xffff)

/**
 * ucs_is_zero_width() - Determine if a Unicode code point is zero-width.
 * @cp: Unicode code point (UCS-4)
 *
 * Return: true if the character is zero-width, false otherwise
 */
bool ucs_is_zero_width(u32 cp)
{
	if (UCS_IS_BMP(cp))
		return cp_in_range16(cp, ucs_zero_width_bmp_ranges,
				     ARRAY_SIZE(ucs_zero_width_bmp_ranges));
	else
		return cp_in_range32(cp, ucs_zero_width_non_bmp_ranges,
				     ARRAY_SIZE(ucs_zero_width_non_bmp_ranges));
}

/**
 * ucs_is_double_width() - Determine if a Unicode code point is double-width.
 * @cp: Unicode code point (UCS-4)
 *
 * Return: true if the character is double-width, false otherwise
 */
bool ucs_is_double_width(u32 cp)
{
	if (UCS_IS_BMP(cp))
		return cp_in_range16(cp, ucs_double_width_bmp_ranges,
				     ARRAY_SIZE(ucs_double_width_bmp_ranges));
	else
		return cp_in_range32(cp, ucs_double_width_non_bmp_ranges,
				     ARRAY_SIZE(ucs_double_width_non_bmp_ranges));
}

/*
 * Structure for base with combining mark pairs and resulting recompositions.

Annotation

Implementation Notes