示例#1
0
static void addSubstitution (Alteration *currAlteration, char* proteinSequenceBeforeIndel, char *proteinSequenceAfterIndel, int indelOffset) 
{
  int lengthBefore,lengthAfter;
  static Stringa buffer = NULL;
  int i;
  int diff;
  int index;

  stringCreateClear (buffer,100);
  index = ((currAlteration->relativePosition - 1) / 3);
  lengthBefore = strlen (proteinSequenceBeforeIndel);
  lengthAfter = strlen (proteinSequenceAfterIndel);
  diff = abs (lengthBefore - lengthAfter);
  if (lengthBefore < lengthAfter) {
    stringPrintf (buffer,"%d_%c->",index + 1,proteinSequenceBeforeIndel[index]);
    for (i = 0; i <= diff; i++) {
      stringAppendf (buffer,"%c",proteinSequenceAfterIndel[index + i]);
    }
  }
  else if (lengthBefore > lengthAfter) {
    stringPrintf (buffer,"%d_",index + 1);
    for (i = 0; i <= diff; i++) {
      stringAppendf (buffer,"%c",proteinSequenceBeforeIndel[index + i]);
    }
    stringAppendf (buffer,"->%c",proteinSequenceAfterIndel[index]);
  }
  else {
    stringPrintf (buffer,"%d_%s->",index,subString (proteinSequenceBeforeIndel,index - 1,index + (int)ceil ((double)indelOffset / 3)));
    stringAppendf (buffer,"%s",subString (proteinSequenceAfterIndel,index - 1,index + (int)ceil ((double)indelOffset / 3)));
  } 
  currAlteration->substitution = hlr_strdup (string (buffer));
}
	List tokenize(char * tokens , char separator , HeapHandler hh){
		
		List list;
		int mark1=0;
		int i;
		char * token;

		if(tokens == NULL)
			return NULL;

		list = buildSringsList(hh);
		
		for(i=0 ; i<(int)strlen(tokens) ; i++){

			if(tokens[i] == separator){
				token = subString(tokens + mark1 , 0 , i-mark1-1 , hh);
				mark1 = i+1;

				if(!equalsStrings(trim(token , hh) , "" ))
					addNode(list , token , hh);
			}

		}
		if(i==strlen(tokens)){
			token = subString(tokens + mark1 ,0, strlen(tokens) - mark1 -1 , hh);

			if(!equalsStrings(trimBlankSpaces(token , hh) , "" ))
				addNode(list , token,  hh);
		}

		return (list->size > 0) ? list : NULL;
	}
示例#3
0
SimpleString SimpleString::subStringFromTill(char startChar, char lastExcludedChar) const
{
    int beginPos = find(startChar);
    if (beginPos < 0) return "";

    int endPos = findFrom((size_t)beginPos, lastExcludedChar);
    if (endPos == -1) return subString((size_t)beginPos, size());

    return subString((size_t)beginPos, (size_t) (endPos - beginPos));
}
示例#4
0
文件: String.cpp 项目: siliace/Bull
    bool String::endsWith(const String& search, bool caseSensitive) const
    {
        if(caseSensitive)
        {
            return subString(getSize() - search.getSize()) == search;

        }

        return subString(getSize() - search.getSize()).toUppercase() == search.toUppercase();
    }
示例#5
0
SimpleString SimpleString::subStringFromTill(char startChar, char lastExcludedChar) const
{
    size_t beginPos = find(startChar);
    if (beginPos == npos) return "";

    size_t endPos = findFrom(beginPos, lastExcludedChar);
    if (endPos == npos) return subString(beginPos);

    return subString(beginPos, endPos - beginPos);
}
示例#6
0
文件: mp3Info.c 项目: fuzzmz/hexchat
struct tagInfo readID3V1(char *file){
//if (DEBUG==1) putlog("reading ID3V1");
	FILE *f;
	struct tagInfo ret;
	int res, i, c, val;
	char *tag;
	char *id;
	char *tmp;
	tag = (char*) malloc(sizeof(char)*129);
	ret.artist=NULL;
	f=fopen(file,"rb");
	if (f==NULL){
       hexchat_print(ph,"file not found while trying to read id3v1");
       //if (DEBUG==1) putlog("file not found while trying to read id3v1");
       return ret;
    }
	//int offset=getSize(file)-128;
	res=fseek(f,-128,SEEK_END);
	if (res!=0) {printf("seek failed\n");fclose(f);return ret;}
	//long int pos=ftell(f);
	//printf("position= %li\n",pos);
	for (i=0;i<128;i++) {
		c=fgetc(f);
		if (c==EOF) {hexchat_printf(ph,"read ID3V1 failed\n");fclose(f);return ret;}
		tag[i]=(char)c;
	}
	fclose(f);
	//printf("tag readed: \n");
	id=substring(tag,0,3);
	//printf("header: %s\n",id);
	if (strcmp(id,"TAG")!=0){hexchat_printf(ph,"no id3 v1 found\n");return ret;}
	ret.title=subString(tag,3,30,1);
	ret.artist=subString(tag,33,30,1);
	ret.album=subString(tag,63,30,1);
	ret.comment=subString(tag,97,30,1);
	tmp=substring(tag,127,1);
	//ret.genre=substring(tag,127,1);
	
	val=(int)tmp[0];
	if (val<0)val+=256;
	//hexchat_printf(ph, "tmp[0]=%i (%i)",val,tmp[0]);
	if ((val<148)&&(val>=0)) 
       ret.genre=GENRES[val];//#############changed
	else {
         ret.genre="unknown";
         //hexchat_printf(ph, "tmp[0]=%i (%i)",val,tmp[0]);
    }
	//hexchat_printf(ph, "tmp: \"%s\" -> %i",tmp,tmp[0]);
	//hexchat_printf(ph,"genre \"%s\"",ret.genre);
	//if (DEBUG==1) putlog("id3v1 extracted");
	return ret;
}
int main (void)
{
//	int stringLength(const char string[]);
	void subString(const char source[], int start, int count, char result[]);
	char result[50];
	subString("character", 4, 3, result);
	printf("%s\n", result);
	subString("two words", 4, 200, result);
	printf("%s\n", result);

	
	return 0;
}
示例#8
0
void ByteArray::trim()
{
	int i;
	int left = 0;
	for (i = 0; i < m_stringLength; ++i)
	{
		if (!isSpace(m_data[i]))
		{
			left = i;
			break;
		}
	}

	int right = m_stringLength;
	for (i = m_stringLength-1; i >= 0; --i)
	{
		if (!isSpace(m_data[i]))
		{
			right = i + 1;
			break;
		}
	}

	int len = right - left;
	if (len < m_stringLength)
	{
		subString(left, len);
	}
}
 void visitChar( char c ) {
     if( m_mode == None ) {
         switch( c ) {
         case ' ': return;
         case '~': m_exclusion = true; return;
         case '[': return startNewMode( Tag, ++m_pos );
         case '"': return startNewMode( QuotedName, ++m_pos );
         default: startNewMode( Name, m_pos ); break;
         }
     }
     if( m_mode == Name ) {
         if( c == ',' ) {
             addPattern<TestSpec::NamePattern>();
             addFilter();
         }
         else if( c == '[' ) {
             if( subString() == "exclude:" )
                 m_exclusion = true;
             else
                 addPattern<TestSpec::NamePattern>();
             startNewMode( Tag, ++m_pos );
         }
     }
     else if( m_mode == QuotedName && c == '"' )
         addPattern<TestSpec::NamePattern>();
     else if( m_mode == Tag && c == ']' )
         addPattern<TestSpec::TagPattern>();
 }
示例#10
0
const str* str::getToken(const char* pSplitter, bool restart)
{
    if(restart || 0 == mpTokenPtr) {
        mpTokenPtr = mpStr;
    }

    str* pTokenStr = 0;
    if('\0' != *mpTokenPtr)
    {
        // Get char* pointer where we see any chars of pSplitter
        char* pFindPtr = strpbrk(mpTokenPtr, pSplitter);
        int indexOfFindPtr = mpTokenPtr-mpStr;
        int tokenLength = 0;

        if(0 == pFindPtr)
        {
            // No chars found, set token to the remaining string:
            tokenLength = strlen(mpTokenPtr);
            mpTokenPtr = mpStr + getLen();
        }
        else {
            // Length of token is from previous token ptr to the find pointer
            tokenLength = (pFindPtr - mpTokenPtr);

            // Set next token pointer to the pointer after the pFindPtr
            mpTokenPtr = pFindPtr+1;
        }
        pTokenStr = (str*)&subString(indexOfFindPtr, tokenLength);
    }

    return pTokenStr;
}
示例#11
0
int main (int argc, char *argv[])
{
  Array breakPoints;
  BreakPoint *currBP;
  int i;
  char *breakPointSequence;

  if ((Conf = confp_open(getenv("FUSIONSEQ_CONFPATH"))) == NULL)
    return EXIT_FAILURE;

  bp_init ("-");
  breakPoints = bp_getBreakPoints ();
  arraySort (breakPoints,(ARRAYORDERF)sortBreakPointsByTargetAndOffset);
  
  for (i = 0; i < arrayMax (breakPoints); i++) {
    currBP = arrp (breakPoints,i,BreakPoint);
    breakPointSequence = getBreakPointSequence (currBP->tileCoordinate1,currBP->tileCoordinate2);
    printf( ">%s|%s\n%s\n", currBP->tileCoordinate1, currBP->tileCoordinate2, breakPointSequence);
    warn(">%s|%s\n%s", 
	 currBP->tileCoordinate1, 
	 currBP->tileCoordinate2, 
	 subString(breakPointSequence, 10, strlen(breakPointSequence)-10));
  }
  bp_deInit();
  confp_close(Conf);

  return EXIT_SUCCESS;
}
quint64 WebSettings::stringToBytes(const QString &srcString)
{
    quint64 bytes = 1;
    QString subString(srcString);

    if (srcString.contains(QChar('k'), Qt::CaseInsensitive) 
            || srcString.contains(QChar('m'), Qt::CaseInsensitive) 
            || srcString.contains(QChar('g'), Qt::CaseInsensitive)) {

        bytes = 1024;
        int pos = srcString.indexOf(QChar('k'), 0, Qt::CaseInsensitive);
        if (pos == -1) {
            bytes *= 1024;
            pos = srcString.indexOf(QChar('m'), 0, Qt::CaseInsensitive);
            if (pos == -1) {
                bytes *= 1024;
                pos = srcString.indexOf(QChar('g'), 0, Qt::CaseInsensitive);
            }
        }

        if (pos != -1)
            subString = srcString.left(pos);
    }

    return subString.toDouble() * bytes;
}
示例#13
0
int String::startsWith(const char* szBegin) const
{
  if (szStr_ == 0) { return 0; }
  String sPrefix = subString(0, UTF8_CharLen(szBegin));
  if (sPrefix.empty()) { return 0; }
  return sPrefix == szBegin;
}
示例#14
0
int main(){

	char *sub = subString("I love C !", 2,4);

	printf("%s", sub);
	
	return 0;
}
	char * getValue(char * line , HeapHandler h){
		char * formated = trim(line , h);
		int indexEqual = indexOfChar(formated , '=');
		if(indexEqual > 0)
			return subString(formated , indexEqual +1 , (int) strlen(formated)-1 , h);
		else
			return NULL;
	}
示例#16
0
	char * getKey(char * line , HeapHandler h){
		char * formated = trim(line , h);
		int indexEqual = indexOfChar(formated , '=');
		if(indexEqual > 0){
			return subString(formated , 0 , indexEqual -1 , h);
		}else{
			return NULL;
		}
	}
示例#17
0
文件: String.cpp 项目: siliace/Bull
    bool String::startsWith(const String& search, bool caseSensitive) const
    {
        if(caseSensitive)
        {
            return find(search) == 0;
        }

        return subString(0, search.getSize()).toUppercase() == search.toUppercase();
    }
示例#18
0
// Calls function: subString(int fromIndex, int charCount)
const str& str::subString(char fromFirstChar, char toLastChar)
{
    const char fi[] = {fromFirstChar, 0x00};
    const char li[] = {toLastChar, 0x00};
    const int firstIndex = firstIndexOf(fi);
    const int lastIndex  =  lastIndexOf(li);

    return subString(firstIndex, lastIndex - firstIndex + 1);
}
示例#19
0
	char * decodePort(char * m , HeapHandler h){
		char * encodedPort , * q , * r;
		int i, found = 0;		
		for(i=0; m[i] != '\0' ; i++){
			if(m[i] == ','){
				found++;
				if(found == 4){
					i++;
					break;
				}
			}
		}
		encodedPort = subString(m , i , strlen(m) , h);

		q = subString(encodedPort , 0 , indexOfString(encodedPort , ",")-1 , h);
		r = subString(encodedPort , indexOfString(encodedPort , ",")+1 , strlen(encodedPort) , h);
		
		return intToString(atoi(q)*256 + atoi(r) , h);		
	}
示例#20
0
void LanguageString::test() {

    // for each string lenght maps the number of strings tested
    QMap<int, int> triesMap;
    // for each string length maps the number of correct test
    QMap<int, int> correctMap;

    // the following length variable indicates the length in words
    for (int length = text.length() / 3; length > 0; --length) {
        for (int i = 0; i < text.length(); ++i) {
            QString substr = subString(length, i);
            if (substr.length() < 3) continue;
            QList<QPair<Language,double> > guessedLanguages =
                    languageGuesser()->identify(substr);
            triesMap[substr.size()] += 1;
            if (!guessedLanguages.empty()) {
                correctMap[substr.size()] +=
                        Language(guessedLanguages.first().first) == language;
            }
       }
    }

    //QTextStream cin(stdin);
    QTextStream cout(stdout);

    cout << "Testing language " << language << "\n";

    //int max = triesMap.keys().last();
    int max = 71;
    int tries = 0;
    int correct = 0;
    int startingFrom = 3;
    for (int i = 3; i <= max; ++i) {
        tries += triesMap.value(i);
        correct += correctMap.value(i);

        if ((i-2)%3 == 0 || i == max) {
            // every 3 iterations and at last iteration
            cout << startingFrom << "-" << i << ": " << correct << "/"
                 << tries << "(" << double(correct) / tries * 100 << "%)\n";
            startingFrom = i+1;
            tries = 0;
            correct = 0;
        }
    }

//    foreach (int size, triesMap.keys()) {
//        int tries = triesMap.value(size);
//        int correct = correctMap.value(size);
//        cout << size << ": " << correct << "/" << tries << "("
//             << double(correct) / tries * 100 << "%)\n";
//    }
    cout << endl;
}
int main()
{
	char* test_null = NULL;
	char test[] = "abcdef";
	char test2[] = "xabcdef";
	printf( "%s\n", test);	
	printf( "%i\n", lengthString( test ));	
	printf( "%i\n", lengthString( test_null ));	
	printf( "%s\n", appendStringToString( test, test2 ));	
	char*  connec = appendStringToString( test, test2 );
	printf( "%i\n", lengthString( connec ));	
	printf( "%s\n", subString( test, 2, 4 ));	
	printf( "%s\n", subString( test, 6, 2 ));	
	printf( "%s\n", subString( test, 4, 4 ));	
	printf( "%s\n", subString( test, 1, lengthString( test )));	
	printf( "%s\n", subString( test, lengthString( test ), 1 ));	
	printf( "%s\n", invertString( invertString ( test )));	
	printf( "%s\n", invertString( test ));	
	 
}
示例#22
0
	char * trim(char * string , HeapHandler h){
		int start = 0;
		int end = strlen(string) -1;

		while(string[start] == ' ')
			start++;

		while(string[end] == ' ' || string[end] == '\n' || string[end] == '\0')
			end--;

		return subString(string , start , end , h);
	}
示例#23
0
	char * decodeHost(char * m , HeapHandler h){
				
		int i, found = 0;
		for(i=0 ; m[i] != '\0' ; i++){
			if(m[i] == ','){
				found++;
				if(found == 4)
					break;
			}
		}		
		return subString(m , 0 , i-1 , h);
	}
示例#24
0
	char * trimNewLine(char * string , HeapHandler h){
		int start = 0;
		int end = (int)strlen(string) -1;

		if (end <= start) return string;

		while(string[start] == ' ')
			start++;

		while(string[end] == '\n')
			end--;

		return subString(string , start , end , h);
	}
示例#25
0
Vector<String> String::split(const String & s)const
{
	Vector<String> res;
	size_t pos=0;
	while(pos < size())
	{
		size_t fpos=findFirst(pos, s);
		if(fpos==SIZE_MAX)
			fpos=size();
		res.pushBack(subString(pos,fpos - pos));
		pos=fpos+s.size();
	}
	return std::move(res);
}
示例#26
0
//shortestString: find the shortest string after concatenation.
int shortestString(char *str1, char *str2) {
    printf("Called \"shortestString\"\n");
    char *first=str1+strlen(str1)-1,*second=str2;
    int len=strlen(str2),flag=0,i=0;
    printf("length of second string is %d and value of first is %s\n",len,first);

    if(!strcmp(str1,str2)) {
        return 1;
        printf("equals and the result is %s\n",str1);
    }
    else {
        if(subString(str1,str2)) {
            return 1;
            printf("%s is subset of %s\n",str2,str1);
        }
        else {
            for(i=1; i<len; i++) {
                printf("inside for loop for %d time\n",i);
                printf("strcmp value %d \n",strncmp(str2,first,i));
                if(strncmp(str2,first,i)==0) {
                    flag=1;
                    --first;
                    printf("after %d pass first value is %s\n",i,first);
                    continue;
                }
                else {
                    --first;

                }
                if(flag==1) {
                    first=str1+strlen(str1)-(i);
                    *++first='\0';
                    strcat(first,str2);
                    printf("first value after concat %s\n",first);
                    return 1;
                    //break;

                }
                //printf("out for loop for %d time\n",i);
            }
            //printf("concatenated string is %s\n",str1);


        }

    }
    printf("return from  \"shortestString\"\n");
    return 0;
}
//readFile, ghi vao mang l[] voi size la so sv truoc khi them
	void readFile(string _file, Student l[], int &size){
		ifstream fin;
		fin.open(_file.c_str());
		if(!fin.is_open())
	    {
	        cout<<"Khong the mo file.\n";
	        exit(1);
	    }else{
	    	string s = "";	    	
	    	while (getline(fin, s)){
				subString(s, l, size);
			}
			fin.close();
	    }	
	}
示例#28
0
文件: utls.cpp 项目: zsummer/breeze
std::string getHostByName(const std::string & name, unsigned short port)
{
    auto ret = subString(name, "https://", false).second;
    ret = subString(ret, "http://", false).second;
    ret += "/";
    ret = subString(ret, "/", true).first;
    if (std::find_if(ret.begin(), ret.end(), [](char ch) {return !isdigit(ch) && ch != '.'; }) == ret.end())
    {
        return ret; //ipv4 
    }
    if (std::find_if(ret.begin(), ret.end(), [](char ch) {return !isxdigit(ch) && ch != ':'; }) == ret.end())
    {
        return ret; //ipv6 
    }
    struct addrinfo *res = nullptr;
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE;
    if (getaddrinfo(ret.c_str(), toString(port).c_str(), &hints, &res) == 0)
    {
        char buf[100] = { 0 };
        if (res->ai_family == AF_INET)
        {
            inet_ntop(res->ai_family, &(((sockaddr_in*)res->ai_addr)->sin_addr), buf, 100);
        }
        else if (res->ai_family == AF_INET6)
        {
            inet_ntop(res->ai_family, &(((sockaddr_in6*)res->ai_addr)->sin6_addr), buf, 100);
        }
        return buf;
    }

    return "";
}
 void addPattern() {
     std::string token = subString();
     if( startsWith( token, "exclude:" ) ) {
         m_exclusion = true;
         token = token.substr( 8 );
     }
     if( !token.empty() ) {
         Ptr<TestSpec::Pattern> pattern = new T( token );
         if( m_exclusion )
             pattern = new TestSpec::ExcludedPattern( pattern );
         m_currentFilter.m_patterns.push_back( pattern );
     }
     m_exclusion = false;
     m_mode = None;
 }
//readFile, ghi vao mang l[] voi size la so gv truoc khi them
	void LecturerList::readFile(string _file){
		ifstream fin;
		fin.open(_file.c_str());
		if(!fin.is_open())
	    {
	        cout<<"Khong the mo file.\n";
	        exit(1);
	    }else{
	    	string s = "";
	    	while (getline(fin, s)){
				subString(s);
			}
			fin.close();
	    }	
	}