//GeoGet 2
//
// Trekbuddy Simple GPX, verze 2010-04-30
// Web:     http://www.zby.cz/geocaching/gge
// License: public domain


function ExportExtension: string;
begin
  result := 'GPX';
end;

function ExportDescription: string;
begin
  result := 'Trekbuddy Simple GPX ------';
end;

function ExportHeader: string;
begin
  Result := '<?xml version="1.0" encoding="utf-8"?>';
  Result := Result + '<gpx>';
end;

function ExportFooter: string;
begin
  result := '</gpx>';
end;

{*
function Utf8SubStr(str:string;  start:integer; length:integer): string;
var val, i, pos : integer;
begin

	pos := 0;
	i := 1;
	while i <= length(str) do begin
	  if (pos>length) then break;
	  
		val := ord(str[i]);
		
		if(val <= 127) then begin  //ascii value
			result := result + str[i];
			inc(pos);
		end
		else if( val >= 194 ) AND ( val <= 223 ) then begin  //194-223 	Start of 2-byte sequence
			if i+1 <= length(str) then begin //enough source chars for 2-bytes
				result := result + str[i];
				i := i+1;
				result := result + str[i];
				
				inc(pos);
			end;			
		end;
		
		inc(i);
	end;
end;
*}

function MySubStr(mystr:string;  start:integer; len:integer): string;
begin
  result := Copy(mystr, start, len);
end;

function fc(str:string):string;
begin
	result := MySubStr(str, 0, 1);
end;

function mycdata(str:string): string;
begin
	result := cdata(str); //kvuli '<' a '&' ...
end;


{*
9k WPTs, load/řazení: 1min, pohyb svižný

all-(eventy & mystery)   střední+prg      prg-all.gpx       2,9k  0,5MB
all-(eventy & mystery)   celá čr          cr-all.gpx        12,9k 2,2MB
multi   + AW + LISTINGY  střední+prg      prg-multi.gpx     1,5k  6,3MB bezls 1MB
mystery + AW + LISTINGY  střední+prg      prg-mystery.gpx   1,5k  8,4MB bezls 2MB

*}

function ExportPoint(): string;
var
  name, cmt: string;
begin
  Result := '';
  
  //name: <dis>?Honzova Mysterka      <GC1234> \n\n Hint: abcd
  if GC.CacheType = 'Unknown Cache' then name := '?'
  else if GC.CacheType = 'Multi-cache' then name := '×'
  else if GC.CacheType = 'Traditional Cache' then name := ''
  else name := '*';
  name := name + GC.Name + '         <'+GC.ID+'>';
	if (GC.Hint <> '') then
		name := name + CRLF + CRLF + GC.Hint;

	if GC.IsDisabled then
		name := '<dis>'+name;
	if GC.IsArchived then
		name := '<archived>'+name;
  
	//gpx result
  result := Result + '<wpt lat="' + GC.Lat + '" lon="' + GC.Lon + '">';
  Result := Result + '<name>' + mycdata(name) +'</name>';
  Result := Result + '<cmt>' + fc(GC.CacheType) + fc(GC.Size) + GC.Difficulty + GC.Terrain +'</cmt>';
	Result := Result + '</wpt>';

end;

