Esempio n. 1
0
int main()
{
    //find
    printf("Found1 at %i\n", findString("chatterbox", "hat"));
    printf("Found2 at %i\n", findString("chatterbox", "att"));
    printf("Found3 at %i\n", findString("chatterbox", "box"));
    printf("Found4 at %i\n", findString("chatterbox", "boxx"));
    
    //remove
    char str3[20] = "chatterbox";
    removeString(str3, 9, 1);
    printf("\nAfter remove1 = %s\n", str3);
    
    char str4[20] = "chatterbox";
    removeString(str4, 9, 2);
    printf("After remove2 = %s\n", str4);
    
    char str5[20] = "chatterbox";
    removeString(str5, 0, 9);
    printf("After remove3 = %s\n", str5);
    
    //insert
    char str8[20] = "the wrong son";
    
    insertString(str8, "per", 14 );
    printf("\nAfter insert1  = %s\n", str8);
    
    insertString(str8, "per", 10 );
    printf("After insert2  = %s\n", str8);
    
    insertString(str8, "You are ", 0);
    printf("After insert3  = %s\n\n", str8);    
    return 0;
}
Esempio n. 2
0
void XMLText_escapeContent(const char *src, const size_t lenSrc, char *&dst, size_t &lenDst)
{
    dst = (char*)src;
    lenDst = lenSrc;
    if(!lenSrc || !src) return;
    char *posFound = strpbrk (dst, "<>&\"");
    while (posFound != 0)
    {
        if(dst == src)//dst not allocated yet
        {
            dst = (char*)malloc(lenSrc + 1);
            lenDst = lenSrc + 1;
            dst[lenSrc] = 0;
            memcpy(dst, src, lenSrc);
            posFound = ((posFound - src) + dst);
        }
        switch(*posFound)
        {
        case '<'://&lt;
            *posFound = '&';
            ++posFound;
            insertString(dst, lenDst , "lt;", 3, posFound);
            posFound = strpbrk (posFound + 1,"<>&\"");
            break;
            
        case '>': //&gt;
            *posFound = '&';
            ++posFound;
            insertString(dst, lenDst, "gt;", 3, posFound);
            posFound = strpbrk (posFound + 1,"<>&\"");
            break;
            
            
        case '&': //&amp;

            *posFound = '&';
            ++posFound;
            insertString(dst, lenDst, "amp;", 4, posFound);
            posFound = strpbrk (posFound + 1,"<>&\"");
            break;

        case '"': //&quot;

            *posFound = '&';
            ++posFound;
            insertString(dst, lenDst, "quot;", 5, posFound);
            posFound = strpbrk (posFound + 1,"<>&\"");
            break;
            
        default:
            //posFound = strpbrk (posFound + 1,"<>&");
            break;
        }

      
    }
    
    if(dst != src) --lenDst;
}
Esempio n. 3
0
/*---------------------------------------------------------------------*/

void StringList_init(StringList *stringList)
{
  assert(stringList != NULL);

  List_init(stringList);
}

void StringList_done(StringList *stringList)
{
  assert(stringList != NULL);

  List_done(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

StringList *StringList_new(void)
{
  return (StringList*)List_new();
}

StringList *StringList_duplicate(const StringList *stringList)
{
  StringList *newStringList;

  assert(stringList != NULL);

  newStringList = StringList_new();
  if (newStringList == NULL)
  {
    return NULL;
  }

  StringList_copy(newStringList,stringList);

  return newStringList;
}

void StringList_copy(StringList *stringList, const StringList *fromStringList)
{
  StringNode *stringNode;

  assert(stringList != NULL);
  assert(fromStringList != NULL);

  stringNode = fromStringList->head;
  while (stringNode != NULL)
  {
    StringList_append(stringList,stringNode->string);
    stringNode = stringNode->next;
  }
}

void StringList_delete(StringList *stringList)
{
  assert(stringList != NULL);

  List_delete(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_clear(StringList *stringList)
{
  assert(stringList != NULL);

  List_clear(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_move(StringList *fromStringList, StringList *toStringList)
{
  assert(fromStringList != NULL);
  assert(toStringList != NULL);

  List_move(fromStringList,toStringList,NULL,NULL,NULL);
}

#ifdef NDEBUG
void StringList_insert(StringList *stringList, const String string, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insert(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertCString(StringList *stringList, const char *s, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertCString(const char *__fileName__, ulong __lineNb__, StringList *stringList, const char *s, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newCString(s),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newCString(__fileName__,__lineNb__,s),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertChar(StringList *stringList, char ch, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertChar(const char *__fileName__, ulong __lineNb__, StringList *stringList, char ch, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newChar(ch),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newChar(__fileName__,__lineNb__,ch),nextStringNode);
  #endif /* NDEBUG */
}
Esempio n. 4
0
/*---------------------------------------------------------------------*/

void StringList_init(StringList *stringList)
{
  assert(stringList != NULL);

  List_init(stringList);
}

void StringList_done(StringList *stringList)
{
  assert(stringList != NULL);

  List_done(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

StringList *StringList_new(void)
{
  return (StringList*)List_new();
}

StringList *StringList_duplicate(const StringList *stringList)
{
  StringList *newStringList;

  assert(stringList != NULL);

  newStringList = StringList_new();
  if (newStringList == NULL)
  {
    return NULL;
  }

  StringList_copy(newStringList,stringList);

  return newStringList;
}

void StringList_copy(StringList *stringList, const StringList *fromStringList)
{
  StringNode *stringNode;

  assert(stringList != NULL);
  assert(fromStringList != NULL);

  stringNode = fromStringList->head;
  while (stringNode != NULL)
  {
    StringList_append(stringList,stringNode->string);
    stringNode = stringNode->next;
  }
}

void StringList_delete(StringList *stringList)
{
  assert(stringList != NULL);

  List_delete(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_clear(StringList *stringList)
{
  assert(stringList != NULL);

  List_clear(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_move(StringList *fromStringList, StringList *toStringList)
{
  assert(fromStringList != NULL);
  assert(toStringList != NULL);

  List_move(fromStringList,toStringList,NULL,NULL,NULL);
}

#ifdef NDEBUG
void StringList_insert(StringList *stringList, const String string, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insert(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertCString(StringList *stringList, const char *s, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertCString(const char *__fileName__, ulong __lineNb__, StringList *stringList, const char *s, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newCString(s),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newCString(__fileName__,__lineNb__,s),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertChar(StringList *stringList, char ch, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertChar(const char *__fileName__, ulong __lineNb__, StringList *stringList, char ch, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newChar(ch),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newChar(__fileName__,__lineNb__,ch),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertBuffer(StringList *stringList, char *buffer, ulong bufferLength, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertBuffer(const char *__fileName__, ulong __lineNb__, StringList *stringList, char *buffer, ulong bufferLength, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newBuffer(buffer,bufferLength),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newBuffer(__fileName__,__lineNb__,buffer,bufferLength),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_append(StringList *stringList, const String string)
#else /* not NDEBUG */
void __StringList_append(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),NULL);
  #endif /* NDEBUG */
}
Esempio n. 5
0
/*---------------------------------------------------------------------*/

void StringList_init(StringList *stringList)
{
  assert(stringList != NULL);

  List_init(stringList);
}

void StringList_done(StringList *stringList)
{
  assert(stringList != NULL);

  List_done(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

StringList *StringList_new(void)
{
  return (StringList*)List_new();
}

StringList *StringList_duplicate(const StringList *stringList)
{
  StringList *newStringList;

  assert(stringList != NULL);

  newStringList = StringList_new();
  if (newStringList == NULL)
  {
    return NULL;
  }

  StringList_copy(newStringList,stringList);

  return newStringList;
}

void StringList_copy(StringList *stringList, const StringList *fromStringList)
{
  StringNode *stringNode;

  assert(stringList != NULL);
  assert(fromStringList != NULL);

  stringNode = fromStringList->head;
  while (stringNode != NULL)
  {
    StringList_append(stringList,stringNode->string);
    stringNode = stringNode->next;
  }
}

void StringList_delete(StringList *stringList)
{
  assert(stringList != NULL);

  List_delete(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_clear(StringList *stringList)
{
  assert(stringList != NULL);

  List_clear(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_move(StringList *fromStringList, StringList *toStringList)
{
  assert(fromStringList != NULL);
  assert(toStringList != NULL);

  List_move(fromStringList,toStringList,NULL,NULL,NULL);
}

#ifdef NDEBUG
void StringList_insert(StringList *stringList, const String string, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insert(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertCString(StringList *stringList, const char *s, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertCString(const char *__fileName__, ulong __lineNb__, StringList *stringList, const char *s, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newCString(s),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newCString(__fileName__,__lineNb__,s),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertChar(StringList *stringList, char ch, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertChar(const char *__fileName__, ulong __lineNb__, StringList *stringList, char ch, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newChar(ch),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newChar(__fileName__,__lineNb__,ch),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertBuffer(StringList *stringList, char *buffer, ulong bufferLength, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertBuffer(const char *__fileName__, ulong __lineNb__, StringList *stringList, char *buffer, ulong bufferLength, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newBuffer(buffer,bufferLength),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newBuffer(__fileName__,__lineNb__,buffer,bufferLength),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_append(StringList *stringList, const String string)
#else /* not NDEBUG */
void __StringList_append(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),NULL);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_appendCString(StringList *stringList, const char *s)
#else /* not NDEBUG */
void __StringList_appendCString(const char *__fileName__, ulong __lineNb__, StringList *stringList, const char *s)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newCString(s),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newCString(__fileName__,__lineNb__,s),NULL);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_appendChar(StringList *stringList, char ch)
#else /* not NDEBUG */
void __StringList_appendChar(const char *__fileName__, ulong __lineNb__, StringList *stringList, char ch)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newChar(ch),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newChar(__fileName__,__lineNb__,ch),NULL);
  #endif /* NDEBUG */
}
Esempio n. 6
0
/*---------------------------------------------------------------------*/

void StringList_init(StringList *stringList)
{
  assert(stringList != NULL);

  List_init(stringList);
}

void StringList_done(StringList *stringList)
{
  assert(stringList != NULL);

  List_done(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

StringList *StringList_new(void)
{
  return (StringList*)List_new();
}

StringList *StringList_duplicate(const StringList *stringList)
{
  StringList *newStringList;

  assert(stringList != NULL);

  newStringList = StringList_new();
  if (newStringList == NULL)
  {
    return NULL;
  }

  StringList_copy(newStringList,stringList);

  return newStringList;
}

void StringList_copy(StringList *stringList, const StringList *fromStringList)
{
  StringNode *stringNode;

  assert(stringList != NULL);
  assert(fromStringList != NULL);

  stringNode = fromStringList->head;
  while (stringNode != NULL)
  {
    StringList_append(stringList,stringNode->string);
    stringNode = stringNode->next;
  }
}

void StringList_delete(StringList *stringList)
{
  assert(stringList != NULL);

  List_delete(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_clear(StringList *stringList)
{
  assert(stringList != NULL);

  List_clear(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_move(StringList *fromStringList, StringList *toStringList)
{
  assert(fromStringList != NULL);
  assert(toStringList != NULL);

  List_move(fromStringList,toStringList,NULL,NULL,NULL);
}

#ifdef NDEBUG
void StringList_insert(StringList *stringList, const String string, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insert(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertCString(StringList *stringList, const char *s, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertCString(const char *__fileName__, ulong __lineNb__, StringList *stringList, const char *s, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newCString(s),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newCString(__fileName__,__lineNb__,s),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertChar(StringList *stringList, char ch, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertChar(const char *__fileName__, ulong __lineNb__, StringList *stringList, char ch, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newChar(ch),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newChar(__fileName__,__lineNb__,ch),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_insertBuffer(StringList *stringList, char *buffer, ulong bufferLength, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insertBuffer(const char *__fileName__, ulong __lineNb__, StringList *stringList, char *buffer, ulong bufferLength, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newBuffer(buffer,bufferLength),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newBuffer(__fileName__,__lineNb__,buffer,bufferLength),nextStringNode);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_append(StringList *stringList, const String string)
#else /* not NDEBUG */
void __StringList_append(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),NULL);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_appendCString(StringList *stringList, const char *s)
#else /* not NDEBUG */
void __StringList_appendCString(const char *__fileName__, ulong __lineNb__, StringList *stringList, const char *s)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newCString(s),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newCString(__fileName__,__lineNb__,s),NULL);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_appendChar(StringList *stringList, char ch)
#else /* not NDEBUG */
void __StringList_appendChar(const char *__fileName__, ulong __lineNb__, StringList *stringList, char ch)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newChar(ch),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newChar(__fileName__,__lineNb__,ch),NULL);
  #endif /* NDEBUG */
}

#ifdef NDEBUG
void StringList_appendBuffer(StringList *stringList, char *buffer, ulong bufferLength)
#else /* not NDEBUG */
void __StringList_appendBuffer(const char *__fileName__, ulong __lineNb__, StringList *stringList, char *buffer, ulong bufferLength)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_newBuffer(buffer,bufferLength),NULL);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_newBuffer(__fileName__,__lineNb__,buffer,bufferLength),NULL);
  #endif /* NDEBUG */
}
Esempio n. 7
0
static StringObject* lookupInternedString(StringObject* strObj, bool isLiteral)
{
    StringObject* found;

    assert(strObj != NULL);
    u4 key = dvmComputeStringHash(strObj);
    dvmLockMutex(&gDvm.internLock);
    if (isLiteral) {
        /*
         * Check the literal table for a match.
         */
        StringObject* literal = lookupString(gDvm.literalStrings, key, strObj);
        if (literal != NULL) {
            /*
             * A match was found in the literal table, the easy case.
             */
            found = literal;
        } else {
            /*
             * There is no match in the literal table, check the
             * interned string table.
             */
            StringObject* interned = lookupString(gDvm.internedStrings, key, strObj);
            if (interned != NULL) {
                /*
                 * A match was found in the interned table.  Move the
                 * matching string to the literal table.
                 */
                dvmHashTableRemove(gDvm.internedStrings, key, interned);
                found = insertString(gDvm.literalStrings, key, interned);
                assert(found == interned);
            } else {
                /*
                 * No match in the literal table or the interned
                 * table.  Insert into the literal table.
                 */
                found = insertString(gDvm.literalStrings, key, strObj);
                assert(found == strObj);
            }
        }
    } else {
        /*
         * Check the literal table for a match.
         */
        found = lookupString(gDvm.literalStrings, key, strObj);
        if (found == NULL) {
            /*
             * No match was found in the literal table.  Insert into
             * the intern table if it does not already exist.
             */
            found = insertString(gDvm.internedStrings, key, strObj);
        }
    }
    assert(found != NULL);
    dvmUnlockMutex(&gDvm.internLock);
    return found;
}
Esempio n. 8
0
/*---------------------------------------------------------------------*/

void StringList_init(StringList *stringList)
{
  assert(stringList != NULL);

  List_init(stringList);
}

void StringList_done(StringList *stringList)
{
  assert(stringList != NULL);

  List_done(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

StringList *StringList_new(void)
{
  return (StringList*)List_new();
}

StringList *StringList_duplicate(const StringList *stringList)
{
  StringList *newStringList;

  assert(stringList != NULL);

  newStringList = StringList_new();
  if (newStringList == NULL)
  {
    return NULL;
  }

  StringList_copy(newStringList,stringList);

  return newStringList;
}

void StringList_copy(StringList *stringList, const StringList *fromStringList)
{
  StringNode *stringNode;

  assert(stringList != NULL);
  assert(fromStringList != NULL);

  stringNode = fromStringList->head;
  while (stringNode != NULL)
  {
    StringList_append(stringList,stringNode->string);
    stringNode = stringNode->next;
  }
}

void StringList_delete(StringList *stringList)
{
  assert(stringList != NULL);

  List_delete(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_clear(StringList *stringList)
{
  assert(stringList != NULL);

  List_clear(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}

void StringList_move(StringList *fromStringList, StringList *toStringList)
{
  assert(fromStringList != NULL);
  assert(toStringList != NULL);

  List_move(fromStringList,toStringList,NULL,NULL,NULL);
}

#ifdef NDEBUG
void StringList_insert(StringList *stringList, const String string, StringNode *nextStringNode)
#else /* not NDEBUG */
void __StringList_insert(const char *__fileName__, ulong __lineNb__, StringList *stringList, const String string, StringNode *nextStringNode)
#endif /* NDEBUG */
{
  #ifdef NDEBUG
    insertString(stringList,String_duplicate(string),nextStringNode);
  #else /* not NDEBUG */
    insertString(__fileName__,__lineNb__,stringList,__String_duplicate(__fileName__,__lineNb__,string),nextStringNode);
  #endif /* NDEBUG */
}
Esempio n. 9
0
struct PrefixTree *loadTree(const char *fileName)
{
    struct PrefixTree *prefixTree = createPrefixTree(32, 127);

    FILE *file = fopen(fileName, "r");

    char str[BUF_SIZE];
    while(fgets(str, BUF_SIZE, file))
    {
        int strLength = strlen(str);

        if(str[strLength - 1] == '\n')
            strLength--;

        if(strLength == 0)
            continue;

        if(str[strLength - 1] == '\r')
            strLength--;

        if(strLength == 0)
            continue;

        insertString(prefixTree, str, strLength);
    }

    fclose(file);

    return prefixTree;
}
Esempio n. 10
0
void
ygu::InsertStringsAtIndentationLevel (StringVector const &collection,
                                      unsigned int       indentation,
                                      size_t             insertPosition,
                                      size_t             replacementEndPos,
                                      std::string        &string)
{
    std::string whitespace (indentation, ' ');
    unsigned int counter = 0;
    unsigned int const collectionSize = collection.size ();

    size_t eraseDistance = replacementEndPos - insertPosition;
    string.erase (insertPosition, eraseDistance);

    for (auto const &str : collection)
    {
        std::stringstream ss;

        /* Only indent the first levels */
        if (counter++)
            ss << whitespace;

        ss << str;

        /* Don't insert newlines at the end of the collection */
        if (counter != collectionSize)
            ss << "\n";

        std::string insertString (ss.str ());
        string.insert (insertPosition, insertString);
        insertPosition += insertString.size ();
    }
}
int main(void){
    char source [100] = "The wrong son.";
    insertString (source, "per", 10);
    
    int i;
    for ( i = 0; i < 100; ++i){
        printf("%c", source[i]);
    }
}
Esempio n. 12
0
long ComboBox::insertString(long index, UINT stringId)
{
    char_t* str = LoadString(stringId);
    if (NULL == str)
        return CB_ERRSPACE;

    long err = insertString(index, str);
    free(str);
    return err;
}
Esempio n. 13
0
sk_sp<SkPDFObject> SkPDFMetadata::MakeDocumentInformationDict(
        const SkDocument::PDFMetadata& metadata) {
    auto dict = sk_make_sp<SkPDFDict>();
    for (const auto keyValuePtr : gMetadataKeys) {
        const SkString& value = metadata.*(keyValuePtr.valuePtr);
        if (value.size() > 0) {
            dict->insertString(keyValuePtr.key, value);
        }
    }
    dict->insertString("Producer", "Skia/PDF m" SKPDF_STRING(SK_MILESTONE));
    if (metadata.fCreation.fEnabled) {
        dict->insertString("CreationDate",
                           pdf_date(metadata.fCreation.fDateTime));
    }
    if (metadata.fModified.fEnabled) {
        dict->insertString("ModDate", pdf_date(metadata.fModified.fDateTime));
    }
    return dict;
}
Esempio n. 14
0
SkPDFObject* SkPDFMetadata::createDocumentInformationDict() const {
    auto dict = sk_make_sp<SkPDFDict>();
    static const char* keys[] = {
            "Title", "Author", "Subject", "Keywords", "Creator"};
    for (const char* key : keys) {
        for (const SkDocument::Attribute& keyValue : fInfo) {
            if (keyValue.fKey.equals(key)) {
                dict->insertString(key, keyValue.fValue);
            }
        }
    }
    dict->insertString("Producer", "Skia/PDF m" SKPDF_STRING(SK_MILESTONE));
    if (fCreation) {
        dict->insertString("CreationDate", pdf_date(*fCreation.get()));
    }
    if (fModified) {
        dict->insertString("ModDate", pdf_date(*fModified.get()));
    }
    return dict.release();
}
Esempio n. 15
0
WString& WCommandList::getCommand( WString& command ) {
/*****************************************************/

    getText( command );
    // make sure that we don't insert empty strings
    if( *((const char *)command) != '\0' && selected() == -1 ) {
        int pos = insertString( command );
        select( pos );
    }
    return command;
}
Esempio n. 16
0
void prefixTreeSample()
{
    struct PrefixTree *prefixTree = createPrefixTree(32, 127);
    insertString(prefixTree, "abcd", 4);
    insertString(prefixTree, "sadr", 4);
    insertString(prefixTree, "fved", 4);
    insertString(prefixTree, "vcefd", 5);

    if(1 == containsString(prefixTree, "abcd", 4))
        printf("Contain 'abcd'\r\n");
    else
        printf("NO 'abcd'\r\n");

    if(1 == containsString(prefixTree, "abc", 3))
        printf("Contain 'abc'\r\n");
    else
        printf("NO 'abc'\r\n");

    deletePrefixTree(prefixTree);
}
Esempio n. 17
0
int addStringToTrie (Tree *codeTrie, int *string, int possition, int *codeCount) {
    int lastPos[1];
    lastPos[0] = possition;
    while (string[possition] != -1) {
        possition = insertString(possition, codeTrie, string, lastPos);
        if (possition == -1) {
            return arrayLen(string);
        }
    }
    return lastPos[0];
}
ARB* insertNewARB(ARB* newARB){
    char* toInsert;
    int again=0;
    printf("\nInserire la stringa da immettere\n");
    do{
        toInsert=insertString();
        newARB=insertARBNode(newARB, toInsert);
        printf("Inserire un'altra stringa?\n0)No\n1)Si\n");
        scanf("%d", &again);
        getchar();
    }while(again);
    return newARB;
}
Esempio n. 19
0
void Client::startRead()
{
    //@puts("reading");
    char *buffer = (char*)malloc(sizeof(char)*10240);
    int bytesAvail = client.bytesAvailable();
    client.read(buffer, bytesAvail);
    buffer[bytesAvail] = '\0';
    int bytesPushed=0;
    int *size=(int*)malloc(sizeof(int));
    Action *action = (Action*)malloc(sizeof(int));
    char *msg;

    //loop through the available messages
    while(bytesPushed<bytesAvail){
    *size=0;
    popMetadata(&buffer,action,size,&msg);
    bytesPushed+=(*size+8);
    if(bytesPushed<=bytesAvail){

        //@printf("Bytes pushed: %i, Bytes available: %i\n",bytesPushed,bytesAvail);
        if(bytesPushed<bytesAvail){
            //@printf("Msg: %s\nData remaining: %s\n\n",msg,buffer);
        } else {
            //@printf("Msg: %s\n\n",msg);
        }
        switch(*action) {
            case KEY_EVENT:
                receiveEvent(stringToEvent(msg));
                break;
            case INSERT_STRING:
                insertString(msg);
                break;
            case REMOVE_STRING:
                removeString(msg);
                break;
            case INITIAL_SEND:
                initialRead(msg);
                break;
            case CURSOR_MOVE:
                if(moveRemoteCursor(msg)) cursorPositionChanged();
                break;
            default:
                puts("We don't take your kind here.");
                break;
        }
    } else {
        puts("Well, that went badly.");
    }
    }
}
Esempio n. 20
0
int main()
{
    printf("Hello world!\n");
    char res ='y';
    while(res=='y')
    {
        char* ins="";
        scanf(" %s",ins);
        insertString(ins);
        printf("vuoi inserire un'altra stringa\n");
        scanf(" %c",res);
    }
    return 0;
}
bool replaceString(char source[], char s1[], char s2[])
{
	int index = findString(source, s1);
	int s1_len = stringLen(s1);

	if (index == -1)
		return false;

	removeString(source, index, s1_len);

	insertString(source, s2, index);

	return true;
}
Esempio n. 22
0
void historyAdd( uchar id, const char *str )
{
    if( str[0] == EOS )
        return;
    startId( id );
    advanceStringPointer();
    while( curRec != 0 )
        {
        if( strcmp( str, curRec->str ) == 0 )
            deleteString();
        advanceStringPointer();
        }
    insertString( id, str );
}
Esempio n. 23
0
void ListBox::setItemText(int index, const TCHAR *str)
{
  int si = getSelectedIndex();
  int top = getTopIndex();
  LRESULT lresult = SendMessage(m_hwnd, LB_GETTOPINDEX, NULL, NULL);
  UINT topIndex = (UINT)lresult;
  _ASSERT(topIndex == lresult);
  LPARAM data = getItemData(index);
  removeString(index);
  insertString(index, str, data);
  if (si == index) {
    setSelectedIndex(si);
  }
  setTopIndex(top);
}
bool replaceString (char source [], char find [], char replace []){
    int findString (const char haystack [], const char needle []);
    void removeString(char string [], int start, int length);
    int lengthOf(char source []);
    void insertString (char source [100], char insert [4], int start);
    
    int start = findString(source, find);
    
    if ( start > -1 ){
        removeString (source, start, lengthOf(find));
        insertString (source, replace, start);
        return true;
    }
    
    return false;   // If the string is not found
}
Esempio n. 25
0
/*  7.7  */
SWmlToken * addTokenWithStr(SDocData *data,
                            UINT16    code,
                            PString   str,
                            ESite     site)
{
/* 
 * Append a new node for 'code' and 'str' to the list of WML tokens.
 * If str has never been seen before, create a new entry for it to remember,
 * otherwise treat the string entry as going to string table of the
 * output stream.
 * Note: site==STR_IN_TABLE only when it was called for unknown element
 *       or attribute.
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  SWmlToken * _node;
  SWmlString * _strEntry = str ? lookupString(data,str) : 0; 

/* Code */

  if(site==STR_OPAQUE_DATE && str && STR_LEN(str)) {
      POOL_ALLOC(DOCPOOL, _strEntry);
      _strEntry->m_string = strXDup(str,DOCPOOL);
      _strEntry->m_site   = STR_OPAQUE_DATE;
      _strEntry->m_offset = ~0;

      SLL_INSERT(data->m_stringTable[0], _strEntry);
  }
  else if(_strEntry) {                      /* it has been seen */
      appendToTbl(data,_strEntry, 0);       /* 0: try to insert */
  }
  else if(str) {
      _strEntry = insertString(data,str);
      if(site==STR_IN_TABLE) {
          appendToTbl(data,_strEntry, 1);   /* 1: must insert   */
      }
  }
  /* If _strEntry is still NULL, it behaves as 'addToken'. */

  POOL_ALLOC(DOCPOOL, _node);
  _node->m_code     = code;
  _node->m_strEntry = _strEntry;
  FIFO_INSERT(data->m_tokenList, _node);
  
  return _node;
}
Esempio n. 26
0
bool replaceString (char text[], const char s1[], const char s2[])
{
    int index = findString (text, s1);

    if ( index >= 0 ) {
        int rm_length = 0;
        while ( s1[rm_length] != '\0' ) {
            ++rm_length;
        }

        removeString (text, index, rm_length);
        insertString (text, s2, index);

        return true;
    } else {
        return false;
    }
}
Esempio n. 27
0
void CTextBox::OnInsertText( const TCHAR* data, int num )
{
    if ( IsFoucus() )
    {
        TString insertString( data, nNum );
        m_strText += insertString;
        auto glyphs = m_pFontFace->GetGlyphs( m_strText );
        m_fCurXoffset = 0;
        CRenderTarget* pCurTarget = CRenderManager::GetInstance()->GetCurrentRenderTarget();
        BEATS_ASSERT(pCurTarget != NULL);
        for ( auto glyph : glyphs )
        {
            m_fCurXoffset +=  glyph->GetWidth() * pCurTarget->GetScaleFactor();
        }
        ParseText();
        UpdateCur();
    }
}
Esempio n. 28
0
bool replaceString (char source[], char find[], char replace[])
{
    int stringLength (const char string[]);
    int findString (const char search[], const char find[]);
    void removeString (char source[], int index, int len);
    void insertString (char source[], char insert[], int index);
    
    int index = findString(source, find);
    
    if (index != -1)
    {
        removeString(source, index, stringLength(find));
        insertString(source, replace, index);
        
        return true;
    }
    
    return false;
}
Esempio n. 29
0
void replaceString(char source[], const char s1[], const char s2[])
{
    int findString(const char s1[], const char s2[]);
    void removeString(char s1[], int start, int counter);
    void insertString(char s1[], const char insert[], int insertNumber);

    int start = findString(source, s1);
    int counter, i = 0;

    while(s1[i] != '\0')
        ++i;

    counter = i;
    while(start != -1)
    {
        removeString(source, start, counter);
        insertString(source, s2, start);
        start = findString(source, s1);
    }
}
Esempio n. 30
0
int main(void) {
	void readLine(char buffer[]);
	void insertString(char source[], const char insertion[], const int position);
	char source[81], insertion[81];
	int position;

	printf("Enter source: ");
	readLine(source);

	printf("Enter insertion string: ");
	readLine(insertion);

	printf("Enter insertion position: ");
	scanf("%i", &position);

	insertString(source, insertion, position);

	printf("The modified string is: \n");
	printf("%s\n", source);

	return 0;
}