Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 112 lines (89 sloc) 1.94 kB
#ifndef com_sleepless_strlist_cpp
#define com_sleepless_strlist_cpp
// Copyright 1998-2004 Sleepless Software Inc. All Rights Reserved
/*
Similar to List, but takes char * instead of void * and uses
different names for some functions, like remove() instead of rem().
This also has sorting functions.
void append(const char *s)
void remove(int n)
void clear()
const char *get(int n)
int find(const char *s)
int findWithCase(const char *s)
void sort()
void sortCase()
int length()
*/
#include "list.cpp"
#include "str.cpp"
struct StrList
{
List list;
// Adds item to end of list. 's' is duplicated, so caller's
// pointer does not need to be preserved.
void append(const char *s)
{
s = strdup(s);
if(s)
list.append((void *)s);
}
// Removes item at index 'n' from list if 'n' is a valid index.
void remove(int n)
{
char *s = (char *)list.rem((int)n);
if(s)
free(s);
}
// Remove all items from list.
void clear()
{
int l = list.length();
for(int i = 0; i < l; i++)
remove(0);
}
// Return read-only pointer to item with index 'n'.
const char *get(int n)
{
return (const char *)list.get(n);
}
// Returns index of first item that matches 's' or -1 if not found.
int find(const char *s)
{
int len = list.length();
for(int i = 0; i < len; i++)
{
const char *ms = (const char *)list.get(i);
if(Str::equals(ms, s))
return i;
}
return -1;
}
// Same as find() but case sensitive
int findWithCase(const char *s)
{
int len = list.length();
for(int i = 0; i < len; i++)
{
const char *ms = (const char *)list.get(i);
if(Str::equalsCase(ms, s))
return i;
}
return -1;
}
// Sorts items on list
void sort()
{
list.sort(Str::compare);
}
// Sorts items on list with case sensitivity.
void sortCase()
{
list.sort(Str::compareCase);
}
int length()
{
return list.length();
}
};
#endif // com_sleepless_strlist_cpp
Jump to Line
Something went wrong with that request. Please try again.