MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / tf_only_add

Function tf_only_add

tests/test_main.c:891–932  ·  view source on GitHub ↗

Adds the token in text[0..length). Surrounding whitespace is not part of it * (the CR of a CRLF file included), and an empty span is not a token. */

Source from the content-addressed store, hash-verified

889/* Adds the token in text[0..length). Surrounding whitespace is not part of it
890 * (the CR of a CRLF file included), and an empty span is not a token. */
891static bool tf_only_add(const char *text, size_t length) {
892 while (length > 0 && isspace((unsigned char)text[0])) {
893 text++;
894 length--;
895 }
896 while (length > 0 && isspace((unsigned char)text[length - 1])) {
897 length--;
898 }
899 if (length == 0) {
900 return true;
901 }
902 /* No test or suite name comes near this; it also bounds the copy below. */
903 const char *colon = length <= CBM_TEST_SELECTION_TOKEN_MAX ? memchr(text, ':', length) : NULL;
904 size_t suite_length = colon ? (size_t)(colon - text) : length;
905 if (length > CBM_TEST_SELECTION_TOKEN_MAX || !tf_only_name_valid(text, suite_length) ||
906 (colon && !tf_only_name_valid(colon + 1, length - suite_length - 1))) {
907 fprintf(stderr, "malformed test selection token: %.*s (expected suite or suite:test)\n",
908 (int)length, text);
909 return false;
910 }
911 if (tf_only_count == tf_only_cap) {
912 size_t cap = tf_only_cap ? tf_only_cap * 2 : CBM_SZ_64;
913 tf_only_token_t *grown = realloc(tf_only_tokens, cap * sizeof(*grown));
914 if (!grown) {
915 fprintf(stderr, "Failed to allocate the test selection\n");
916 return false;
917 }
918 tf_only_tokens = grown;
919 tf_only_cap = cap;
920 }
921 char *copy = malloc(length + 1);
922 if (!copy) {
923 fprintf(stderr, "Failed to allocate the test selection\n");
924 return false;
925 }
926 memcpy(copy, text, length);
927 copy[suite_length] = '\0';
928 copy[length] = '\0';
929 tf_only_tokens[tf_only_count++] = (tf_only_token_t){
930 .suite = copy, .test = copy + suite_length + (colon ? 1 : 0), .state = TF_ONLY_UNSEEN};
931 return true;
932}
933
934static bool tf_only_add_list(const char *list) {
935 for (const char *cursor = list;;) {

Callers 2

tf_only_add_listFunction · 0.85
tf_only_add_fileFunction · 0.85

Calls 1

tf_only_name_validFunction · 0.85

Tested by

no test coverage detected