summaryrefslogtreecommitdiffstats
path: root/kcontrol/css/template.cpp
blob: e237ed7964965289ea8d76b3b08608dfc02b17a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45


#include <tqfile.h>


#include "template.h"


bool CSSTemplate::expand(TQString destname, const TQMap<TQString,TQString> &dict)
{
  TQFile inf(_filename);
  if (!inf.open(IO_ReadOnly))
    return false;
  TQTextStream is(&inf);
  
  TQFile outf(destname);
  if (!outf.open(IO_WriteOnly))
    return false;
  TQTextStream os(&outf);

  TQString line;
  while (!is.eof())
    {
      line = is.readLine();

      int start = line.find('$');
      if (start >= 0)
	{
	  int end = line.find('$', start+1);
	  if (end >= 0)
            {
	      TQString expr = line.mid(start+1, end-start-1);
	      TQString res = dict[expr];

	      line.replace(start, end-start+1, res);
	    }
	}
      os << line << endl;
    }  

  inf.close();
  outf.close();

  return true;
}