1b99bc125d897c0712377c4fb4d23ff9f6cbca9f angie Fri Feb 25 11:43:27 2011 -0800 New src/inc/regexHelper.h module replaces the regex conveniencefunctions that were previously down in hg/lib/hgFindSpecCustom.c. The primary motivation for this is so I can use regex functions in the new src/lib/vcf.c for Feature #2821 (VCF parser), but I hope this will make it easier in general to use regexes in any new code. diff --git src/hg/lib/hgFind.c src/hg/lib/hgFind.c index 0e7dbcb..152eea4 100644 --- src/hg/lib/hgFind.c +++ src/hg/lib/hgFind.c @@ -1,18 +1,18 @@ /* hgFind.c - Find things in human genome annotations. */ #include "common.h" -#include <regex.h> +#include "regexHelper.h" #include "obscure.h" #include "hCommon.h" #include "portable.h" #include "dystring.h" #include "hash.h" #include "cheapcgi.h" #include "htmshell.h" #include "web.h" #include "jksql.h" #include "hdb.h" #include "hui.h" #include "psl.h" #include "genePred.h" #include "genePredReader.h" #include "bed.h" @@ -1178,31 +1178,31 @@ if ((row = sqlNextRow(sr)) != NULL) { if (mrnaType != NULL) *mrnaType = cloneString(row[0]); ret = TRUE; } else ret = FALSE; sqlFreeResult(&sr); return ret; } boolean isRefSeqAcc(char *acc) /* Return TRUE if acc looks like a RefSeq acc. */ { -return matchRegex(acc, "^(N|X)M_[0-9]{6}[0-9]*$"); +return regexMatchNoCase(acc, "^(N|X)M_[0-9]{6}[0-9]*$"); } static char *mrnaType(char *db, char *acc) /* Return "mrna" or "est" if acc is mRNA, otherwise NULL. Returns * NULL for refseq mRNAs */ /* for compat with older databases, just look at the seqId to * determine if it's a refseq, don't use table */ /* NOTE: caller must free returned type */ { struct sqlConnection *conn; char *type = NULL; char *ret = NULL; if (isRefSeqAcc(acc)) return NULL; @@ -2793,31 +2793,31 @@ int relStart, int relEnd, boolean multiTerm) /* Perform the search described by hfs on term. If successful, put results * in hgp and return TRUE. (If not, don't modify hgp.) */ { struct slPair *xrefList = NULL, *xrefPtr = NULL; boolean found = FALSE; if (hfs == NULL || term == NULL || hgp == NULL) errAbort("NULL passed to hgFindUsingSpec.\n"); if (strlen(term)<2 && ! (sameString(hfs->searchName, "knownGene") || sameString(hfs->searchName, "flyBaseGeneSymbolOneLetter"))) return FALSE; -if (isNotEmpty(hfs->termRegex) && ! matchRegex(term, hfs->termRegex)) +if (isNotEmpty(hfs->termRegex) && ! regexMatchNoCase(term, hfs->termRegex)) return(FALSE); if (! hTableOrSplitExists(db, hfs->searchTable)) return(FALSE); if (isNotEmpty(hfs->searchType) && searchSpecial(db, hfs, term, hgp, relativeFlag, relStart, relEnd, &found)) return(found); if (isNotEmpty(hfs->xrefTable)) { struct sqlConnection *conn = hAllocConn(db); boolean exists = sqlTableExists(conn, hfs->xrefTable); hFreeConn(&conn); if (! exists) @@ -3009,42 +3009,39 @@ hgp->query = cloneString(term); hgp->database = db; if (extraCgi == NULL) extraCgi = ""; hgp->extraCgi = cloneString(extraCgi); if (singleSearch(db, term, cart, hgp)) return hgp; /* Allow any search term to end with a :Start-End range -- also support stuff * pasted in from BED (chrom start end) or SQL query (chrom | start | end). * If found, strip it off and remember the start and end. */ char *originalTerm = term; if ((canonicalSpec = - matchRegexSubstr(term, canonicalRangeExp, - substrs, ArraySize(substrs))) || + regexMatchSubstrNoCase(term, canonicalRangeExp, substrs, ArraySize(substrs))) || (gbrowserSpec = - matchRegexSubstr(term, gbrowserRangeExp, - substrs, ArraySize(substrs))) || + regexMatchSubstrNoCase(term, gbrowserRangeExp, substrs, ArraySize(substrs))) || (lengthSpec = - matchRegexSubstr(term, lengthRangeExp, - substrs, ArraySize(substrs))) || - matchRegexSubstr(term, bedRangeExp, substrs, ArraySize(substrs)) || + regexMatchSubstrNoCase(term, lengthRangeExp, substrs, ArraySize(substrs))) || + regexMatchSubstrNoCase(term, bedRangeExp, substrs, ArraySize(substrs)) || (singleBaseSpec = - matchRegexSubstr(term, singleBaseExp, substrs, ArraySize(substrs))) || - matchRegexSubstr(term, sqlRangeExp, substrs, ArraySize(substrs))) + regexMatchSubstrNoCase(term, singleBaseExp, substrs, ArraySize(substrs))) || + regexMatchSubstrNoCase(term, sqlRangeExp, substrs, ArraySize(substrs))) { term = cloneString(term); /* Since we got a match, substrs[1] is the chrom/term, [2] is relStart, * [3] is relEnd. ([0] is all.) */ term[substrs[1].rm_eo] = 0; eraseTrailingSpaces(term); term[substrs[2].rm_eo] = 0; relStart = atoi(stripCommas(term+substrs[2].rm_so)); term[substrs[3].rm_eo] = 0; if (singleBaseSpec) { relEnd = relStart; relStart--; } else