1 |
#include "../../String/StringInput.h"
|
2 |
#include "../../System/System.h"
|
3 |
#include "StringTest.h"
|
4 |
#include "../../System/SystemDefine.h"
|
5 |
#include "../../LinkedList/ObjectLinkedList.h"
|
6 |
#include "../../Array/ObjectArray.h"
|
7 |
#include "../../String/ExtPropertiesElement.h"
|
8 |
#include "../../Files/FileHandler.h"
|
9 |
#include "../../LinkedList/StringLinkedList.h"
|
10 |
#include "../../LinkedList/ObjectLinkedList.h"
|
11 |
#include "../../Element/ObjectLinkElement.h"
|
12 |
#include "../../MatrisList/ObjectMatrisList.h"
|
13 |
#include "../../Array/ObjectArray.h"
|
14 |
|
15 |
StringTest::StringTest()
|
16 |
{
|
17 |
|
18 |
}
|
19 |
|
20 |
StringTest::~StringTest(){}
|
21 |
|
22 |
void StringTest::run()
|
23 |
{
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
/*
|
29 |
|
30 |
String arne="kalle";
|
31 |
String arne2="456";
|
32 |
String arne3="456";
|
33 |
|
34 |
if ( arne2.equals(arne))
|
35 |
{
|
36 |
System::println("true");
|
37 |
}
|
38 |
else
|
39 |
{
|
40 |
System::println("false");
|
41 |
}
|
42 |
|
43 |
if ( arne2.equals("456"))
|
44 |
{
|
45 |
System::println("true");
|
46 |
}
|
47 |
|
48 |
|
49 |
System::println(arne2.toInt()); //convert a string to a int
|
50 |
System::println(arne2.toFloat()); //convert a string to a float
|
51 |
|
52 |
// parse a int to a string add it together to another string
|
53 |
|
54 |
for ( int b=0 ; b<5 ; b++ )
|
55 |
{
|
56 |
String result=arne+(b+1);
|
57 |
System::println(result);
|
58 |
}
|
59 |
|
60 |
float number=0;
|
61 |
|
62 |
for ( int f=0 ; f<5 ; f++ )
|
63 |
{
|
64 |
number=number+0.1f;
|
65 |
|
66 |
String result=arne+number;
|
67 |
System::println(result);
|
68 |
}
|
69 |
|
70 |
// adding floats together with strings
|
71 |
|
72 |
float kalle2=20;
|
73 |
|
74 |
String arn2=10.1232f;
|
75 |
|
76 |
String result2=arn2+kalle2;
|
77 |
|
78 |
System::println(result2);
|
79 |
|
80 |
// adding ints together with strings
|
81 |
|
82 |
int kalle3=20;
|
83 |
|
84 |
String arn3=10;
|
85 |
|
86 |
// String result3=arn3+kalle3;
|
87 |
|
88 |
System::println(arn3+kalle3);
|
89 |
*/
|
90 |
|
91 |
/*
|
92 |
String *test = new String("kalle");
|
93 |
String *test2 = new String("argha");
|
94 |
|
95 |
String *test3=test+test2;
|
96 |
|
97 |
delete test;
|
98 |
delete test2;
|
99 |
*/
|
100 |
/*
|
101 |
String filePath=".html";
|
102 |
|
103 |
if (filePath.checkFileFormat(".html"))
|
104 |
{
|
105 |
System::println("true");
|
106 |
}
|
107 |
else
|
108 |
{
|
109 |
System::println("false");
|
110 |
}
|
111 |
|
112 |
String filePath2="../kkkk/duck/../../kalle/";
|
113 |
// String filePath="/kalle/../";
|
114 |
|
115 |
String rightFilePath="/kalle/";
|
116 |
|
117 |
if (filePath2.theFilePathIsNotUnder(rightFilePath))
|
118 |
{
|
119 |
System::println("true");
|
120 |
}
|
121 |
else
|
122 |
{
|
123 |
System::println("false");
|
124 |
}
|
125 |
*/
|
126 |
/*
|
127 |
ObjectLinkedList2<ExtPropertiesElement> *list = new ObjectLinkedList2<ExtPropertiesElement>();
|
128 |
|
129 |
String key="arne";
|
130 |
String data="blaha";
|
131 |
|
132 |
list->addLast(new ExtPropertiesElement(key.buffer,data.buffer));
|
133 |
|
134 |
String key2="arne2";
|
135 |
String data2="blaha2";
|
136 |
|
137 |
list->addLast(new ExtPropertiesElement(key2.buffer,data2.buffer));
|
138 |
|
139 |
for ( int i=0; i<list->size() ; i++ )
|
140 |
{
|
141 |
ExtPropertiesElement *temp=list->getElement(i);
|
142 |
System::println(temp->key);
|
143 |
}
|
144 |
|
145 |
delete list;
|
146 |
*/
|
147 |
/*
|
148 |
String filePath2="../kkkk/duck/../../kalle/";
|
149 |
// String filePath="/kalle/../";
|
150 |
|
151 |
String rightFilePath="/kalle/";
|
152 |
|
153 |
if (filePath2.theFilePathIsNotUnder(rightFilePath))
|
154 |
{
|
155 |
System::println("true");
|
156 |
}
|
157 |
else
|
158 |
{
|
159 |
System::println("false");
|
160 |
}
|
161 |
*/
|
162 |
/*
|
163 |
int size=3;
|
164 |
|
165 |
ObjectMatrisList<String> *objectMatris = new ObjectMatrisList<String>(size);
|
166 |
|
167 |
objectMatris->addColumnInRow(new String("arne"),0);
|
168 |
objectMatris->addColumnInRow(new String("kalle"),1);
|
169 |
objectMatris->addColumnInRow(new String("peter"),2);
|
170 |
|
171 |
objectMatris->addRow();
|
172 |
|
173 |
objectMatris->addColumnInRow(new String("arne2"),0);
|
174 |
objectMatris->addColumnInRow(new String("kalle2"),1);
|
175 |
objectMatris->addColumnInRow(new String("peter2"),2);
|
176 |
|
177 |
objectMatris->addRow();
|
178 |
|
179 |
objectMatris->sortColumnInLargestOrder(0);
|
180 |
|
181 |
for ( int r=0; r<objectMatris->rowSize() ; r++)
|
182 |
{
|
183 |
ObjectArray<String> *objectArray=objectMatris->getRow(0,r);
|
184 |
|
185 |
for ( int i=0; i<objectMatris->columnSize() ; i++)
|
186 |
{
|
187 |
System::print(objectArray->getObject(i));
|
188 |
}
|
189 |
System::println("k");
|
190 |
}
|
191 |
|
192 |
delete objectMatris;
|
193 |
|
194 |
*/
|
195 |
/*
|
196 |
String filePath="Root/";
|
197 |
|
198 |
StringLinkedList *fileList=FileHandler::listDirectory(filePath);
|
199 |
|
200 |
ObjectLinkedList<ObjectLinkElement> *fileNameList = new ObjectLinkedList<ObjectLinkElement>();
|
201 |
ObjectLinkedList<ObjectLinkElement> *fileSizeList = new ObjectLinkedList<ObjectLinkElement>();
|
202 |
|
203 |
int size=fileList->size();
|
204 |
|
205 |
for ( int i=0; i<size ; i++ )
|
206 |
{
|
207 |
String fileName=fileList->getElement(i);
|
208 |
String fileSize=FileHandler::getFileSize(filePath + fileName);
|
209 |
|
210 |
ObjectLinkElement *fileSizeElement = new ObjectLinkElement(fileSize);
|
211 |
ObjectLinkElement *fileNameElement = new ObjectLinkElement(fileName);
|
212 |
|
213 |
fileNameElement->rightChild=fileSizeElement;
|
214 |
fileSizeElement->leftChild=fileNameElement;
|
215 |
|
216 |
fileNameList->addLast(fileNameElement, fileName);
|
217 |
fileSizeList->addLast(fileSizeElement, fileSize);
|
218 |
}
|
219 |
|
220 |
|
221 |
// fileNameList->sortLargestOrder();
|
222 |
|
223 |
int fSize=fileNameList->size();
|
224 |
|
225 |
for ( int f=0; f<fSize ; f++ )
|
226 |
{
|
227 |
String fileNameInfo="FileName: ";
|
228 |
System::println(fileNameInfo + (fileNameList->getElement(f))->data + " FileSize: " + (fileNameList->getElement(f))->rightChild->data);
|
229 |
}
|
230 |
|
231 |
fileSizeList->sortSmallestOrder();
|
232 |
|
233 |
for ( int f2=0; f2<fSize ; f2++ )
|
234 |
{
|
235 |
String fileNameInfo="FileSize: ";
|
236 |
System::println(fileNameInfo + (fileSizeList->getElement(f2))->data + " FileName: " + (fileSizeList->getElement(f2))->leftChild->data + " length " + (fileSizeList->getElement(f2))->data->length);
|
237 |
}
|
238 |
|
239 |
*/
|
240 |
|
241 |
/*
|
242 |
String data;
|
243 |
|
244 |
data+="kalle";
|
245 |
|
246 |
System::println(data);
|
247 |
|
248 |
String data2;
|
249 |
|
250 |
data2+=1000;
|
251 |
|
252 |
System::println(data2);
|
253 |
|
254 |
String data3;
|
255 |
|
256 |
data3+=0.5f;
|
257 |
|
258 |
System::println(data3);
|
259 |
|
260 |
String data4;
|
261 |
|
262 |
data4+=NewRow();
|
263 |
|
264 |
System::println(data4);
|
265 |
|
266 |
String data5;
|
267 |
String dataName="arne";
|
268 |
|
269 |
data5+=dataName;
|
270 |
|
271 |
System::println(data5);
|
272 |
|
273 |
String data6;
|
274 |
String *dataName2 = new String("hej");
|
275 |
|
276 |
data6+=dataName2;
|
277 |
|
278 |
System::println(data6);
|
279 |
|
280 |
delete dataName2;
|
281 |
*/
|
282 |
|
283 |
/*
|
284 |
String data="test";
|
285 |
|
286 |
data+="kalle";
|
287 |
|
288 |
System::println(data);
|
289 |
|
290 |
String data2="test";
|
291 |
|
292 |
data2+=1000;
|
293 |
|
294 |
System::println(data2);
|
295 |
|
296 |
String data3="test";
|
297 |
|
298 |
data3+=0.5f;
|
299 |
|
300 |
System::println(data3);
|
301 |
|
302 |
String data4="test";
|
303 |
|
304 |
data4+=NewRow();
|
305 |
|
306 |
System::println(data4);
|
307 |
|
308 |
String data5="test";
|
309 |
String dataName="arne";
|
310 |
|
311 |
data5+=dataName;
|
312 |
|
313 |
System::println(data5);
|
314 |
|
315 |
String data6="test";
|
316 |
String *dataName2 = new String("hej");
|
317 |
|
318 |
data6+=dataName2;
|
319 |
|
320 |
System::println(data6);
|
321 |
|
322 |
delete dataName2;
|
323 |
*/
|
324 |
/*
|
325 |
String peter;
|
326 |
String arne;
|
327 |
|
328 |
System::println((int)arne.buffer);
|
329 |
|
330 |
String data=peter + arne;
|
331 |
|
332 |
System::println(data);
|
333 |
*/
|
334 |
/*
|
335 |
String arne=(int)1000;
|
336 |
|
337 |
System::println(arne);
|
338 |
System::println(arne.length);
|
339 |
|
340 |
String arne2=10.1232f;
|
341 |
|
342 |
System::println(arne2);
|
343 |
System::println(arne2.length);
|
344 |
|
345 |
String arne3="kalle";
|
346 |
|
347 |
String arne4=arne3 + arne2;
|
348 |
|
349 |
System::println(arne4);
|
350 |
System::println(arne4.length);
|
351 |
|
352 |
String arne5=1.01f;
|
353 |
|
354 |
System::println(arne5);
|
355 |
System::println(arne5.length);
|
356 |
|
357 |
String arne6=0.0123f;
|
358 |
|
359 |
System::println(arne6);
|
360 |
System::println(arne6.length);
|
361 |
*/
|
362 |
|
363 |
/*
|
364 |
String tt="arne";
|
365 |
String result=tt + (int)1234;
|
366 |
|
367 |
System::println(result);
|
368 |
System::println(result.length);
|
369 |
|
370 |
String ff="arne";
|
371 |
String result2=ff + 0.1234f;
|
372 |
|
373 |
System::println(result2);
|
374 |
System::println(result2.length);
|
375 |
*/
|
376 |
/*
|
377 |
|
378 |
String ff="kalle";
|
379 |
|
380 |
String result3=ff + NewRow();
|
381 |
|
382 |
System::print(result3);
|
383 |
System::println(result3.length);
|
384 |
*/
|
385 |
/*
|
386 |
String *blah = new String("hej");
|
387 |
|
388 |
String kalle="balle";
|
389 |
|
390 |
String kalle2="balle2";
|
391 |
|
392 |
String kalle3=kalle+blah;
|
393 |
|
394 |
System::println(kalle3);
|
395 |
System::println(kalle3.length);
|
396 |
|
397 |
String arne="bla";
|
398 |
|
399 |
// float ff=0;
|
400 |
|
401 |
for ( int i=0; i<3 ; i++)
|
402 |
{
|
403 |
arne+=blah;
|
404 |
// ff+=0.1f;
|
405 |
}
|
406 |
|
407 |
delete blah;
|
408 |
|
409 |
|
410 |
|
411 |
System::println(arne);
|
412 |
System::println(arne.length);
|
413 |
*/
|
414 |
/*
|
415 |
String arne="200";
|
416 |
String kalle="1000";
|
417 |
|
418 |
if (StringTools::isStringValueSmaller(arne.buffer,arne.length,kalle.buffer,kalle.length))
|
419 |
{
|
420 |
System::println("smaller");
|
421 |
}
|
422 |
else
|
423 |
{
|
424 |
System::println("larger");
|
425 |
}
|
426 |
*/
|
427 |
/*
|
428 |
String filePath="arneAnders/?nisse/kalle.gif";
|
429 |
String tempPath=filePath;
|
430 |
|
431 |
filePath.cutTheBack('/');
|
432 |
|
433 |
System::println(filePath);
|
434 |
System::println(filePath.length);
|
435 |
|
436 |
tempPath.cutTheBegining('/');
|
437 |
|
438 |
System::println(tempPath);
|
439 |
System::println(tempPath.length);
|
440 |
|
441 |
String tempPath2=tempPath;
|
442 |
|
443 |
tempPath.cutTheBack('/');
|
444 |
|
445 |
System::println(tempPath);
|
446 |
System::println(tempPath.length);
|
447 |
|
448 |
tempPath2.cutTheBegining('/');
|
449 |
|
450 |
System::println(tempPath2);
|
451 |
System::println(tempPath2.length);
|
452 |
|
453 |
|
454 |
if (tempPath.isFrontPartEqualTo("?"))
|
455 |
{
|
456 |
System::println("yes");
|
457 |
}
|
458 |
else
|
459 |
{
|
460 |
System::println("no");
|
461 |
}
|
462 |
*/
|
463 |
/*
|
464 |
tempPath.cutTheBegining('/');
|
465 |
System::println(filePath);
|
466 |
*/
|
467 |
|
468 |
FileHandler fileHandler;
|
469 |
|
470 |
ObjectLinkedList<FileInfo> *list=fileHandler.listDirectory("Root/");
|
471 |
|
472 |
int size=list->size();
|
473 |
|
474 |
for ( int i=0; i<size ; i++ )
|
475 |
{
|
476 |
FileInfo *fileInfo=list->getElement(i);
|
477 |
System::println(fileInfo->name);
|
478 |
System::println(fileInfo->size);
|
479 |
System::println(fileInfo->lastModified);
|
480 |
if (fileInfo->directory)
|
481 |
{
|
482 |
System::println("Directory");
|
483 |
}
|
484 |
else
|
485 |
{
|
486 |
System::println("File");
|
487 |
}
|
488 |
}
|
489 |
|
490 |
delete list;
|
491 |
|
492 |
|
493 |
FileInfo *fileInfo=fileHandler.getFileInfo("Root/");
|
494 |
|
495 |
if (fileInfo->directory)
|
496 |
{
|
497 |
System::println("Directory");
|
498 |
}
|
499 |
else
|
500 |
{
|
501 |
System::println("File");
|
502 |
}
|
503 |
|
504 |
|
505 |
} |