Función que acorta una cadena basada en un mapeo de términos / abreviatura con casos especiales -- java campo con algorithm campo con strings campo con regex camp codereview Relacionados El problema

Function that shortens a String based on a term/abbreviation mapping with special cases


4
vote

problema

Español

Esta es una actualización de esta pregunta Dado que los requisitos de esta tarea cambiados.

Tengo una función que toma una descripción como un String y devuelve una versión reducida de la descripción.

El acortamiento se realiza al verificar si una palabra coincide con la clave del Map<String,String> MAPPER y reemplaza la palabra por su abreviatura definida como el valor en el Map . Si la palabra no se puede encontrar en el #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 0 no será reemplazado (se mantiene igual).

Si el valor de una palabra es #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 1 La palabra se eliminará de la cadena de salida

Si el valor de una palabra / carácter es #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 2 Todo después de esa palabra / carácter se eliminará de la cadena de salida.

Si el valor de una palabra / carácter es #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 3 Todo después de esa palabra / carácter se eliminará de la cadena de salida. Incluyendo la palabra / carácter en sí

Si el valor de una palabra es #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 4 Todo lo que se puede quitar con esa palabra se eliminará de la cadena de salida

Puede haber múltiples abreviaturas para la misma palabra.

Control de ganancia automático - & gt; AGC

control - & gt; Ctrl

En cualquier caso, la función siempre debe tomar la abreviatura que toma la mayoría de las palabras.

Ejemplo

Mapa que contiene las siguientes entradas:

Control de ganancia automático - & gt; AGC

control - & gt; Ctrl

identificador - & gt; ID

el - & gt; #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 5

. - & gt; #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 6

: - & gt; #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 7

th - & gt; #include "list.h" #include <stdbool.h> #include <stdlib.h> typedef struct list_t { void** p_table; size_t size; size_t capacity; size_t head; size_t mask; } list_t; static const size_t MINIMUM_CAPACITY = 16; static size_t max(size_t a, size_t b) { return a < b ? b : a; } static size_t fix_initial_capacity(size_t initial_capacity) { size_t ret = 1; initial_capacity = max(initial_capacity, MINIMUM_CAPACITY); while (ret < initial_capacity) ret <<= 1; return ret; } list_t* list_t_alloc(size_t initial_capacity) { list_t* p_ret = malloc(sizeof(*p_ret)); if (!p_ret) return NULL; initial_capacity = fix_initial_capacity(initial_capacity); p_ret->p_table = malloc(sizeof(void*) * initial_capacity); if (!p_ret->p_table) { free(p_ret); return NULL; } p_ret->capacity = initial_capacity; p_ret->mask = initial_capacity - 1; p_ret->head = 0; p_ret->size = 0; return p_ret; } static bool ensure_capacity_before_add(list_t* p_list) { void** p_new_table; size_t i; size_t new_capacity; if (p_list->size < p_list->capacity) return true; new_capacity = 2 * p_list->capacity; p_new_table = malloc(sizeof(void*) * new_capacity); if (!p_new_table) return false; for (i = 0; i < p_list->size; ++i) { p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask]; } free(p_list->p_table); p_list->p_table = p_new_table; p_list->capacity = new_capacity; p_list->mask = new_capacity - 1; p_list->head = 0; return true; } bool list_t_push_front(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->head = (p_list->head - 1) & p_list->mask; p_list->p_table[p_list->head] = p_element; p_list->size++; return true; } bool list_t_push_back(list_t* p_list, void* p_element) { if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element; p_list->size++; return true; } bool list_t_insert(list_t* p_list, size_t index, void* p_element) { size_t elements_before; size_t elements_after; size_t i; size_t head; size_t mask; size_t size; if (!p_list) return false; if (!ensure_capacity_before_add(p_list)) return false; if (index > p_list->size) return false; elements_before = index; elements_after = p_list->size - index; head = p_list->head; mask = p_list->mask; size = p_list->size; if (elements_before < elements_after) { /* Move preceding elements one position to the left. */ for (i = 0; i < elements_before; ++i) { p_list->p_table[(head + i - 1) & mask] = p_list->p_table[(head + i) & mask]; } head = (head - 1) & mask; p_list->p_table[(head + index) & mask] = p_element; p_list->head = head; } else { /* Move the following elements one position to the right. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + size - i) & mask] = p_list->p_table[(head + size - i - 1) & mask]; } p_list->p_table[(head + index) & mask] = p_element; } p_list->size++; return true; } size_t list_t_size(list_t* p_list) { return p_list ? p_list->size : 0; } void* list_t_get(list_t* p_list, size_t index) { if (!p_list) return NULL; if (index >= p_list->size) return NULL; return p_list->p_table[(p_list->head + index) & p_list->mask]; } void* list_t_set(list_t* p_list, size_t index, void* p_new_value) { void* p_ret; if (!p_list) return NULL; if (index >= p_list->size) return NULL; p_ret = p_list->p_table[(p_list->head + index) & p_list->mask]; p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value; return p_ret; } void* list_t_pop_front(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[p_list->head]; p_list->head++; p_list->size--; return p_ret; } void* list_t_pop_back(list_t* p_list) { void* p_ret; if (!p_list) return NULL; if (p_list->size == 0) return NULL; p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask]; p_list->size--; return p_ret; } void* list_t_remove_at(list_t* p_list, size_t index) { void* p_ret; size_t head; size_t mask; size_t elements_before; size_t elements_after; size_t i; size_t j; if (!p_list) return NULL; if (index >= p_list->size) return NULL; head = p_list->head; mask = p_list->mask; p_ret = p_list->p_table[(head + index) & mask]; elements_before = index; elements_after = p_list->size - index - 1; if (elements_before < elements_after) { /* Move the preceding elements one position to the right. */ for (i = 0, j = elements_before; i < elements_before; ++i, --j) { p_list->p_table[(head + j) & mask] = p_list->p_table[(head + j - 1) & mask]; } p_list->head = (head + 1) & mask; } else { /* Move the following elements one position to the left. */ for (i = 0; i < elements_after; ++i) { p_list->p_table[(head + index + i) & mask] = p_list->p_table[(head + index + i + 1) & mask]; } } p_list->size--; return p_ret; } bool list_t_contains(list_t* p_list, void* p_element, bool (*p_equals_function)(void*, void*)) { size_t i; if (!p_list) return false; if (!p_equals_function) return false; for (i = 0; i < p_list->size; ++i) { if (p_equals_function(p_element, p_list->p_table[(p_list->head + i) & p_list->mask])) { return true; } } return false; } void list_t_clear(list_t* p_list) { if (!p_list) return; p_list->head = 0; p_list->size = 0; } void list_t_free(list_t* p_list) { if (!p_list) return; free(p_list->p_table); free(p_list); } 8

Entrada:

El identificador de control superior: XYZ

Salida:

ID de CTRL superior:

Entrada:

Lorem Impsum Th control automático de ganancia. Esto será eliminado

Salida:

th agc

código

  #include "list.h" #include <stdbool.h> #include <stdlib.h>  typedef struct list_t {     void** p_table;     size_t size;     size_t capacity;     size_t head;     size_t mask; } list_t;  static const size_t MINIMUM_CAPACITY = 16;  static size_t max(size_t a, size_t b) {     return a < b ? b : a; }  static size_t fix_initial_capacity(size_t initial_capacity) {     size_t ret = 1;      initial_capacity = max(initial_capacity, MINIMUM_CAPACITY);      while (ret < initial_capacity) ret <<= 1;      return ret; }  list_t* list_t_alloc(size_t initial_capacity) {     list_t* p_ret = malloc(sizeof(*p_ret));      if (!p_ret) return NULL;      initial_capacity = fix_initial_capacity(initial_capacity);      p_ret->p_table = malloc(sizeof(void*) * initial_capacity);      if (!p_ret->p_table)     {         free(p_ret);         return NULL;     }      p_ret->capacity = initial_capacity;     p_ret->mask     = initial_capacity - 1;     p_ret->head     = 0;     p_ret->size     = 0;      return p_ret; }  static bool ensure_capacity_before_add(list_t* p_list) {     void** p_new_table;     size_t i;     size_t new_capacity;      if (p_list->size < p_list->capacity) return true;      new_capacity = 2 * p_list->capacity;     p_new_table  = malloc(sizeof(void*) * new_capacity);      if (!p_new_table) return false;      for (i = 0; i < p_list->size; ++i)      {         p_new_table[i] = p_list->p_table[(p_list->head + i) & p_list->mask];     }      free(p_list->p_table);     p_list->p_table  = p_new_table;     p_list->capacity = new_capacity;     p_list->mask     = new_capacity - 1;     p_list->head     = 0;      return true; }  bool list_t_push_front(list_t* p_list, void* p_element) {     if (!p_list)                             return false;     if (!ensure_capacity_before_add(p_list)) return false;      p_list->head = (p_list->head - 1) & p_list->mask;     p_list->p_table[p_list->head] = p_element;     p_list->size++;     return true; }  bool list_t_push_back(list_t* p_list, void* p_element) {     if (!p_list)                             return false;     if (!ensure_capacity_before_add(p_list)) return false;      p_list->p_table[(p_list->head + p_list->size) & p_list->mask] = p_element;     p_list->size++;     return true; }  bool list_t_insert(list_t* p_list, size_t index, void* p_element) {     size_t elements_before;     size_t elements_after;     size_t i;     size_t head;     size_t mask;     size_t size;      if (!p_list)                             return false;     if (!ensure_capacity_before_add(p_list)) return false;     if (index > p_list->size)                return false;      elements_before = index;     elements_after  = p_list->size - index;     head            = p_list->head;     mask            = p_list->mask;     size            = p_list->size;      if (elements_before < elements_after)      {         /* Move preceding elements one position to the left. */         for (i = 0; i < elements_before; ++i)         {             p_list->p_table[(head + i - 1) & mask] =             p_list->p_table[(head + i) & mask];         }          head = (head - 1) & mask;         p_list->p_table[(head + index) & mask] = p_element;         p_list->head = head;     }     else     {         /* Move the following elements one position to the right. */         for (i = 0; i < elements_after; ++i)         {             p_list->p_table[(head + size - i) & mask] =             p_list->p_table[(head + size - i - 1) & mask];         }          p_list->p_table[(head + index) & mask] = p_element;     }      p_list->size++;     return true; }  size_t list_t_size(list_t* p_list)  {     return p_list ? p_list->size : 0; }  void* list_t_get(list_t* p_list, size_t index) {     if (!p_list)               return NULL;     if (index >= p_list->size) return NULL;      return p_list->p_table[(p_list->head + index) & p_list->mask]; }  void* list_t_set(list_t* p_list, size_t index, void* p_new_value)  {     void* p_ret;      if (!p_list)               return NULL;     if (index >= p_list->size) return NULL;      p_ret = p_list->p_table[(p_list->head + index) & p_list->mask];     p_list->p_table[(p_list->head + index) & p_list->mask] = p_new_value;     return p_ret; }  void* list_t_pop_front(list_t* p_list) {     void* p_ret;      if (!p_list)           return NULL;        if (p_list->size == 0) return NULL;      p_ret = p_list->p_table[p_list->head];     p_list->head++;     p_list->size--;     return p_ret; }  void* list_t_pop_back(list_t* p_list) {     void* p_ret;      if (!p_list)           return NULL;     if (p_list->size == 0) return NULL;      p_ret = p_list->p_table[(p_list->head + p_list->size - 1) & p_list->mask];     p_list->size--;     return p_ret; }  void* list_t_remove_at(list_t* p_list, size_t index) {     void* p_ret;     size_t head;     size_t mask;     size_t elements_before;     size_t elements_after;     size_t i;     size_t j;      if (!p_list)               return NULL;     if (index >= p_list->size) return NULL;      head = p_list->head;     mask = p_list->mask;      p_ret = p_list->p_table[(head + index) & mask];      elements_before = index;     elements_after  = p_list->size - index - 1;      if (elements_before < elements_after)     {         /* Move the preceding elements one position to the right. */         for (i = 0, j = elements_before; i < elements_before; ++i, --j)         {             p_list->p_table[(head + j) & mask] =             p_list->p_table[(head + j - 1) & mask];         }          p_list->head = (head + 1) & mask;     }     else     {         /* Move the following elements one position to the left. */         for (i = 0; i < elements_after; ++i)          {             p_list->p_table[(head + index + i) & mask] =             p_list->p_table[(head + index + i + 1) & mask];         }     }      p_list->size--;     return p_ret; }  bool list_t_contains(list_t* p_list,                          void* p_element,                         bool (*p_equals_function)(void*, void*)) {     size_t i;      if (!p_list)            return false;     if (!p_equals_function) return false;      for (i = 0; i < p_list->size; ++i)      {         if (p_equals_function(p_element,                                p_list->p_table[(p_list->head + i) &                                p_list->mask]))         {             return true;         }     }      return false; }  void list_t_clear(list_t* p_list) {     if (!p_list) return;      p_list->head = 0;     p_list->size = 0; }  void list_t_free(list_t* p_list) {     if (!p_list) return;      free(p_list->p_table);     free(p_list); } 9  

Como puede ver, necesito un patrón regular diferente para el @SuppressWarnings("unchecked") public static <T, K> K[] toArray(ITemplateCommand<T, K> command, List<T> templates) { if (null == templates) { return (K[]) Array.newInstance(command.getClassOfK(), 0); } K[] array = (K[]) Array.newInstance(command.getClassOfK(), templates.size()); for (int i = 0; i < templates.size(); i++) { array[i] = command.buildTemplate(templates.get(i)); } return array; } 0 y @SuppressWarnings("unchecked") public static <T, K> K[] toArray(ITemplateCommand<T, K> command, List<T> templates) { if (null == templates) { return (K[]) Array.newInstance(command.getClassOfK(), 0); } K[] array = (K[]) Array.newInstance(command.getClassOfK(), templates.size()); for (int i = 0; i < templates.size(); i++) { array[i] = command.buildTemplate(templates.get(i)); } return array; } 1 casos para lograr la salida correcta. Para los otros casos, un regeo que busca palabras está bien. Siento que el @SuppressWarnings("unchecked") public static <T, K> K[] toArray(ITemplateCommand<T, K> command, List<T> templates) { if (null == templates) { return (K[]) Array.newInstance(command.getClassOfK(), 0); } K[] array = (K[]) Array.newInstance(command.getClassOfK(), templates.size()); for (int i = 0; i < templates.size(); i++) { array[i] = command.buildTemplate(templates.get(i)); } return array; } 2 podría ser mejorado. Devolviendo el @SuppressWarnings("unchecked") public static <T, K> K[] toArray(ITemplateCommand<T, K> command, List<T> templates) { if (null == templates) { return (K[]) Array.newInstance(command.getClassOfK(), 0); } K[] array = (K[]) Array.newInstance(command.getClassOfK(), templates.size()); for (int i = 0; i < templates.size(); i++) { array[i] = command.buildTemplate(templates.get(i)); } return array; } 3 temprano para los casos especiales parece que no podría causar errores, pero hasta ahora que me ha funcionado.

El @SuppressWarnings("unchecked") public static <T, K> K[] toArray(ITemplateCommand<T, K> command, List<T> templates) { if (null == templates) { return (K[]) Array.newInstance(command.getClassOfK(), 0); } K[] array = (K[]) Array.newInstance(command.getClassOfK(), templates.size()); for (int i = 0; i < templates.size(); i++) { array[i] = command.buildTemplate(templates.get(i)); } return array; } 4 está poblado leyendo el contenido de un archivo delimitado por pestaña.

Original en ingles

This is a update of this question since the requirements for this task changed.

I have a function that takes a description as a String and returns a shortened version of the description.

The shortening is done by checking if a word matches the key of the Map<String,String> MAPPER and replaces the word by its abbreviation defined as the value in the Map. If the word cannot be found in the Map it will not be replaced (it stays the same).

If the value of a word is <remove> the word will be removed from the output string

If the value of a word/character is <remove after> everything after that word/character will be removed from the output string.

If the value of a word/character is <remove after incl> everything after that word/character will be removed from the output string. Including the word/character itself

If the value of a word is <remove before> everything up to that word will removed from the output string

There can be multiple abbreviations for the same word.

AUTOMATIC GAIN CONTROL --> AGC

CONTROL --> CTRL

In any case the function should always take the abbreviation which takes the most words.

Example

Map containing following entries:

AUTOMATIC GAIN CONTROL --> AGC

CONTROL --> CTRL

IDENTIFIER --> ID

THE --> <remove>

. --> <remove after incl>

: --> <remove after>

TH --> <remove before>

Input:

The top control identifier: xyz

Output:

top CTRL ID:

Input:

Lorem impsum TH automatic gain control. This will be deleted

Output:

TH AGC

Code

public final class Shortener {      public static String mappingFile="";     private static final Comparator<String> KEY_COMPARATOR = new Comparator<String>() {         @Override         public int compare(String s1, String s2) {             int diff = Integer.valueOf(s2.length()).compareTo(Integer.valueOf(s1.length()));                         return diff == 0 ? s1.compareToIgnoreCase(s2) : diff;         }     };     private static Map<String,String> MAPPER;      public static String shortenText(String input) {         StringBuilder result = new StringBuilder(input);         for (Map.Entry<String, String> entry : MAPPER.entrySet()) {             Matcher matcher;             if (entry.getValue().equals("<remove after>") || entry.getValue().equals("<remove after incl>")){                 matcher = Pattern.compile("(?i).*" + entry.getKey() + ".*").matcher(result);             }             else matcher = Pattern.compile("(?i)\\b" + entry.getKey() + "\\b").matcher(result);              while (matcher.reset().find()) {                 if (entry.getValue().equals("<remove after>")){                     result.delete(result.indexOf(entry.getKey())+entry.getKey().length(),result.length());                     return result.toString();                 }                 if (entry.getValue().equals("<remove after incl>")){                     result.delete(result.indexOf(entry.getKey()),result.length());                     return result.toString();                 }                 if (entry.getValue().equals("<remove before>")){                     result.delete(0,result.indexOf(entry.getKey()));                     return result.toString();                 }                  result.replace(matcher.start(), matcher.end(), entry.getValue());                  if (entry.getValue().isEmpty() && result.length() != 0) {                                        result.deleteCharAt(matcher.start());                                    }                            }                    }         return result.toString();     }      public static void importMap() {         FileInputStream fstream;         MAPPER = new TreeMap<String, String>(KEY_COMPARATOR);         try {             if(mappingFile.isEmpty()) {                          String fileSperator = System.getProperty("file.separator");                 String shortenerConfigPath = System.getProperty("user.dir")+fileSperator+"config"+fileSperator+"shortener.ini";                 mappingFile = shortenerConfigPath;             }             fstream = new FileInputStream(mappingFile);             BufferedReader br = new BufferedReader(new InputStreamReader(fstream));              String strLine;              while ((strLine = br.readLine()) != null){               String[] arr = strLine.split("\t");               if (arr.length!=2){                   System.out.println("Error Shortener import");               }               else {                   if (arr[1].equals("<remove>")){                       MAPPER.put(arr[0], "");                   }                   else MAPPER.put(arr[0], arr[1]);               }             }                        br.close();                } catch (FileNotFoundException e) {             e.printStackTrace();         } catch (IOException e) {             e.printStackTrace();         }      }  } 

As you can see I need a different regex pattern for the <remove after> and <remove after incl> cases in order to achieve the correct output. For the other cases a regex that looks for words is ok. I feel like the shortenText() could be improved. Returning the String early for the special cases seems like it would cause errors but so far that has worked for me.

The Map MAPPER is populated by reading the contents of a tab delimited file.

           
     
     

Lista de respuestas

3
 
vote
vote
La mejor respuesta
 

soy yo otra vez. :)

Cita ¡TU REGEX!

Su código está roto porque se olvidó de quote(".") , que lleva significado especial en la regex . Sin cotización:

  Pattern.compile("(?i).*..*")   

coincidirá con casi cualquier cosa, al menos un personaje de largo, pero luego lo siguiente fallará por las líneas que no contienen un carácter literal 99887776655544332 , lanzando un StringIndexOutOfBoundsException : < / p>

   if (entry.getValue().equals("<remove after incl>")){     result.delete(result.indexOf(entry.getKey()),result.length());     return result.toString(); }   

Devoluciones tempranas

Devolver el String

Temprano a los casos especiales parece que no podría causar errores, pero hasta ahora que ha funcionado para mí.

Esto no funciona para su segundo ejemplo, como su método 9988776655544336 "Después de eliminar el texto antes de TH y no recorta ". This will be deleted" < / Código>. Creo que está buscando break fuera del Pattern.compile("(?i).*..*") 0 -loop en lugar de volver:

  Pattern.compile("(?i).*..*") 1  

Llamables

Una vez más, como anteriormente cubierto En su pregunta anterior, no se recomienda el marcador de posición 99887776655443312 , especialmente ahora que tiene más valores para cubrir. Un error tipográfico de Pattern.compile("(?i).*..*") 3 a Pattern.compile("(?i).*..*") 4 potencialmente hará la depuración dolorosamente duro a las 3 am.

Estado, y lectura de archivos

SOLO PARA ELABROATE ligeramente en La respuesta de @mattputnnnam , debe considerar hacer un 99887776655443315 < / Código> instancia por- Pattern.compile("(?i).*..*") 6 , en lugar de hacer el campo Pattern.compile("(?i).*..*") 7 . Esto hace que el uso de cada caso sea más claro, ya que están atados a un archivo de asignación. ¿Qué puede permanecer Pattern.compile("(?i).*..*") 8 es su método Pattern.compile("(?i).*..*") 9 , aunque creo que debería estar tomando en un argumento en la ubicación del archivo y devolviendo el 9988776655544332020 deseado .

En una nota relacionada, creo que esto puede estar en un método en sí, como incumplir con un archivo de asignación cuando el argumento dado no es válido, no es realmente parte del manejo de lectura de archivos, pero lo lodea.

  "."1  

Encapsulación

Ahora que tiene diferentes 998877666554433222 Expresiones y manejo para atender, es posible que desee considerar ponerlos en clases que encapsula estos estados y comportamientos para cada par de objetivo / reemplazo.

Por ejemplo, puede tener una clase 998877766555443323234443323

  "."4  

Puede tener algunos métodos estáticos que le permitan especificar, utilizando nombres de métodos legibles, el comportamiento deseado. Por ejemplo:

  "."5  

Aquí, "."6

es un 99887776655443327 que maneja las acciones solicitadas:

  "."8  

y sí, para los fanáticos de Java 8 con un ojo agudo, 99887766555443329 debe implementar StringIndexOutOfBoundsException0 y 998877766554433331 debe implementar StringIndexOutOfBoundsException2 .

 

It's me again. :)

Quote your regex!

Your code is broken because you forgot to quote("."), which carries special meaning in regex. Without quoting:

Pattern.compile("(?i).*..*") 

Will match pretty much anything at least a character long, but then the following will fail for lines that do not contain a literal "." character, throwing a StringIndexOutOfBoundsException:

 if (entry.getValue().equals("<remove after incl>")){     result.delete(result.indexOf(entry.getKey()),result.length());     return result.toString(); } 

Early returns

Returning the String early for the special cases seems like it would cause errors but so far that has worked for me.

This does not work for your second example, as your shortenText() method 'gives up' after removing the text before TH and does not trim away ". This will be deleted". I think you are looking to break out of the while-loop instead of returning:

while (matcher.reset().find()) {     if (entry.getValue().equals("<remove after>")){         result.delete(result.indexOf(entry.getKey()) + entry.getKey().length(),                         result.length());         break;     }     if (entry.getValue().equals("<remove after incl>")){         result.delete(result.indexOf(entry.getKey()), result.length());         break;     }     if (entry.getValue().equals("<remove before>")){         result.delete(0, result.indexOf(entry.getKey()));         break;     }     result.replace(matcher.start(), matcher.end(), entry.getValue());     if (entry.getValue().isEmpty() && result.length() != 0) {                            result.deleteCharAt(matcher.start());     }                }     

Placeholders

Once again, as previously covered in your earlier question, using a String-based placeholder is not recommended, especially now that you have more values to cover. A typo from <remove after incl> to <remove atfer incl will potentially make debugging painfully hard at 3 am.

State, and file reading

Just to elabroate slightly on @MattPutnam's answer, you should consider making a Shortener instance per-mappingFile, instead of making the field public static. This makes the usage of each instance clearer, as they are tied to one mapping file. What can remain static is your importMap() method, though I think it should be taking in an argument to the file's location, and returning the desired Map.

On a related note, I think this can be in a method itself, as defaulting to a mapping file when the given argument is invalid isn't really part of the file-reading handling, but predates it.

private static String getOrDefault(String mappingFile) {     if(mappingFile == null || mappingFile.isEmpty()) {                  String fileSperator = System.getProperty("file.separator");         return System.getProperty("user.dir") + fileSperator +                  "config" + fileSperator + "shortener.ini";     }     return mappingFile; } 

Encapsulation

Now that you have different Pattern expressions and handling to cater, you may want to consider putting them into classes that encapsulates these states and behaviors for each target/replacement pair.

For example, you can have a Processor class that internalizes what to look for, and how to handle it:

public static final class Processor {     private final String target;     private final String replacement;     private final Pattern pattern;     private final Action action;      // StringBuilder instances will be passed to this method for manipulation     public void accept(StringBuilder result) { ... } } 

It can have some static methods that lets you specify, using readable method names, the desired behavior. For example:

private static final Set<Processor> MAPPER = getMapper();  private static Set<Processor> getMapper() {     // PROCESSOR_COMPARATOR will compare Processor instances     // in a similar way to how the 'keys' aka targets are sorted     Set<Processor> mapper = new TreeSet<Processor>(PROCESSOR_COMPARATOR);     mapper.add(Processor.remove("THE"));     mapper.add(Processor.replace("AUTOMATIC GAIN CONTROL", "AGC"));     mapper.add(Processor.replace("CONTROL", "CTRL"));     mapper.add(Processor.replace("IDENTIFIER", "ID"));     mapper.add(Processor.removeBefore("TH"));     mapper.add(Processor.removeAfterIncluding("."));     mapper.add(Processor.removeAfter(":"));     return mapper; } 

Over here, Action is an enum that handles the requested actions:

enum Action {     REPLACE {         // replacement implementation goes here         public void accept(StringBuilder result, Processor processor) { ... }     },     REMOVE_BEFORE {         // remove-before implementation goes here         public void accept(StringBuilder result, Processor processor) { ... }     },     REMOVE_AFTER {         // remove-after implementation goes here         public void accept(StringBuilder result, Processor processor) { ... }     },     REMOVE_AFTER_INCL {         // remove-after-including implementation goes here         public void accept(StringBuilder result, Processor processor) { ... }     }; } 

And yes, for the Java 8 fans with a keen eye, Processor should implement Consumer<StringBuilder> and Action should implement BiConsumer<StringBuilder, Processor>.

 
 
         
         
4
 
vote

Debe ser posible hacer shortenText() más eficiente, pero como está escrito, creo que está bastante claro y no tuve ningún problema descifrado, lo cual es bueno. Una versión más optimizada es probable que sea mucho más difícil de entender, por lo que diría que solo se preocupe por ello si se convierte en un problema.

while (matcher.reset().find()) es sospechoso pero creo que veo por qué lo hiciste.

Mi comentario principal es que al hacer todo estático, solo puede tener un acortamiento, y usarlo es un poco raro. Debe inicializarlo cambiando los campos estáticos y llame a los métodos estáticos en un orden específico. Sería mejor hacer una clase adecuada, por lo que podría crear varios acortados con diferentes archivos de asignación, y también limpiar la interfaz. Como usuario de esta utilidad, me gustaría escribir:

  Shortener s1 = new Shortener(path_to_file); foo(s1.shorten(someString)); Shortener s2 = new Shortener(another_path_to_file); foo(s2.shorten(someString));   
 

It should be possible to make shortenText() more efficient, but as it's written I think it's pretty clear and I had no problem deciphering it, which is good. A more optimized version would likely be much harder to understand, so I would say only worry about it if it becomes a problem.

while (matcher.reset().find()) is suspicious but I think I see why you did that.

My main comment is that by making everything static, you can only ever have one shortener, and using it is kind of weird. You have to initialize it by changing static fields and calling static methods in a specific order. It would be better to make a proper class, so you could create multiple shorteners with different mapping files, and also clean up the interface. As a user of this utility, I would want to write:

Shortener s1 = new Shortener(path_to_file); foo(s1.shorten(someString)); Shortener s2 = new Shortener(another_path_to_file); foo(s2.shorten(someString)); 
 
 
 
 

Relacionados problema

4  Resaltador de sintaxis para HTML y PHP  ( Syntax highlighter for html and php ) 
He creado una aplicación JavaScript para resaltar la sintaxis de HTML y PHP. Sé que muchos resaltadores de sintaxis están disponibles hoy en día, acabo de cre...

8  Mapa-Reduce la implementación para dividir cadenas  ( Map reduce implementation for splitting strings ) 
He estado cambiando este código y no puedo hacerlo mucho mejor. Cambié un poco de la estructura, reinvemé una nueva función para dividir las cadenas que es má...

5  Regex coinciden para una cadena en una URL  ( Regex match for a string in a url ) 
Siento que hay un código repetitivo aquí. Todo lo que estoy haciendo es hacer un partido de regex básico para una cadena en la URL. Si se encuentra una coin...

2  Validando múltiples parámetros por regex y longitud  ( Validating multiple parameters by regex and length ) 
Tengo un conjunto de funciones de validación que devuelven un código de respuesta junto con un mensaje de error si la validación falla. Las solicitudes pueden...

4  Uso eficiente de la expresión regular y la manipulación de cadenas  ( Efficient use of regular expression and string manipulation ) 
La siguiente es mi solución a java vs c ++ . Creo que la forma en que he usado, la biblioteca de RE es ineficiente, y es posible erróneas, ya que estoy obten...

3  ¿Simplificar la expresión regular? (Conversión de Fracciones Unicode a Tex)  ( Simplify regular expression converting unicode fractions to tex ) 
Fondo Estoy convirtiendo el texto Unicode a tex para tipingetting. En la entrada, estoy permitiendo fracciones simples como ½ y ⅔ usando caracteres únic...

2  Función de validación de forma para reaccionar  ( Form validation function for react ) 
Necesito validar varios campos de entrada usando reaccionar. Estoy usando un bloque simple if-común para cada campo de entrada, pero me gustaría optimizar mi ...

6  Cómo reducir esta función de detección de archivo y hacer que sea compatible con comodines  ( How to reduce this archive detection function and make it supports wildcards ) 
La siguiente función se llama para determinar si un archivo dado es el archivo de otro archivo. También estoy buscando una forma de apoyar a los comodines. Po...

5  Realización de un procedimiento para cada formulario  ( Performing a procedure for each form edit ) 
Soy un poco nuevo para programar. Tengo algunas ediciones en mi forma, y ​​para cada edición completada tendrá que hacer un procedimiento. Actualmente, uso ...

1  Nombre de la bahía Pirata y MAILER MAILER  ( Pirate bay name and magnet mailer ) 
Entonces, primera vez que trato PHP. Pensé que me gustaría establecer un objetivo para mí, dividirlo en problemas más pequeños y comenzar a andar en Google. A...




© 2022 respuesta.top Reservados todos los derechos. Centro de preguntas y respuestas reservados todos los derechos