Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/lib/util/substring.cc @ 3530

Last change on this file since 3530 was 3530, checked in by chris, 19 years ago

orxonox/branches/levelloader: Got the system to compile, the basic backbone now runs. What remains to be done is implementing all necessary functions to load all vital classes into a world

File size: 1.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Christian Meyer
13   co-programmer: ...
14*/
15
16
17/**
18   \brief breaks a string into parts that were initially seperated by comma
19   \param string the string to break into substrings
20*/
21
22#include "substring.h"
23
24SubString::SubString( const char* string)
25{
26        n = 0;
27       
28        assert( string != NULL);
29       
30        for( int i = 0; i < strlen(string); i++) if( string[i] == ',') n++;
31
32        n += 1;
33       
34        strings = new char*[n];
35       
36        int i = 0;
37        int l = 0;
38       
39        const char* offset = string;
40        char* end = strchr( string, ',');
41        while( end != NULL)
42        {
43                l = end - offset;
44                strings[i] = new char[l + 1];
45                strncpy( strings[i], offset, l);
46                i++;
47                end++;
48                offset = end;
49                end = strchr( string, ',');
50        }
51       
52        strings[i] = new char[l + 1];
53        strncpy( strings[i], offset, l);
54        l = strlen( offset);
55}
56
57/**
58   \brief removes the object from memory
59*/
60SubString::~SubString()
61{
62        for( int i = 0; i < n; i++)
63        {
64                delete strings[i];
65        }
66       
67        delete strings;
68}
69
70/**
71   \brief get the amount of substrings
72   \returns the amount of substrings
73*/
74int SubString::getN()
75{
76        return n;
77}
78
79/**
80   \brief get a particular substring
81   \param i the ID of the substring to return
82   \returns the designated substring or NULL if an invalid ID was given
83*/
84const char* SubString::getString( int i)
85{
86        if( i < n && i >= 0) return strings[i];
87        else return NULL;
88}
Note: See TracBrowser for help on using the repository browser.