-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUrl.h
More file actions
1340 lines (1124 loc) · 56.4 KB
/
Copy pathUrl.h
File metadata and controls
1340 lines (1124 loc) · 56.4 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include <vector>
NS_BEGIN
// Forward declarations
class CDomainName8;
class CDomainNameW;
class CUrlPathSegment8;
class CUrlPathSegmentW;
class CUrlParameter8;
class CUrlParameterW;
class CUrl8;
class CUrlW;
#ifdef _WIN32
// Windows headers interfere with this definition
#undef SetPort
#endif
//#################################################################################################
class CDomainName8 final
{
private:
friend class CDomainNameW;
public:
// Constructs an empty object
CDomainName8(void) = default;
// Copy and move constructors
CDomainName8(const CDomainName8 &src);
CDomainName8(CDomainName8 &&src) noexcept;
// Constructs an object set to the string/character
explicit CDomainName8(const CDomainNameW &domain);
explicit CDomainName8(const CStr8 &str);
explicit CDomainName8(const CStrW &str);
explicit CDomainName8(PCSTR sz);
explicit CDomainName8(PCWSTR sz);
explicit CDomainName8(const char ch);
explicit CDomainName8(const wchar_t ch);
~CDomainName8(void);
// Returns a pointer to the raw string data
operator PCSTR(void) const noexcept;
PCSTR Get(void) const noexcept;
// Returns the length in characters
size_t GetLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes
size_t GetSize(const bool bIncludeNullTerm = false) const noexcept;
// Empties the string
void Empty(void);
// Returns whether the string is empty
bool IsEmpty(void) const noexcept;
// Returns a UTF8 copy of the object
CDomainName8 AsUtf8(void) const;
// Returns a wchar_t copy of the object
CDomainNameW AsWide(void) const;
#ifdef _WIN32
CDomainNameW AsNative(void) const;
#else
CDomainName8 AsNative(void) const;
#endif
// Copy and move assignment operators
CDomainName8 &operator=(const CDomainName8 &src);
CDomainName8 &operator=(CDomainName8 &&src) noexcept;
// Assigns the object to the string/character
CDomainName8 &operator=(const CDomainNameW &domain);
CDomainName8 &operator=(const CStr8 &str);
CDomainName8 &operator=(const CStrW &str);
CDomainName8 &operator=(PCSTR sz);
CDomainName8 &operator=(PCWSTR sz);
CDomainName8 &operator=(const char ch);
CDomainName8 &operator=(const wchar_t ch);
// Assigns the object to the string/character, returns an error code
ERRCODE Assign(const CDomainName8 &domain);
ERRCODE Assign(const CDomainNameW &domain);
ERRCODE Assign(const CStr8 &str);
ERRCODE Assign(const CStrW &str);
ERRCODE Assign(PCSTR sz);
ERRCODE Assign(PCWSTR sz);
ERRCODE Assign(const char ch);
ERRCODE Assign(const wchar_t ch);
friend std::ostream &operator<<(std::ostream &stream, const CDomainName8 &domain);
// Default compare operators are case insensitive
// After all "GOOGLE.COM" and "google.com" are the same site
// For case sensitive compares use the Compare() function
// Tests for equal
bool operator==(const CDomainName8 &domain) const;
bool operator==(const CStr8 &str) const;
bool operator==(PCSTR sz) const;
bool operator==(const char ch) const;
// Tests for not equal
bool operator!=(const CDomainName8 &domain) const;
bool operator!=(const CStr8 &str) const;
bool operator!=(PCSTR sz) const;
bool operator!=(const char ch) const;
// Tests for less than
bool operator<(const CDomainName8 &domain) const;
bool operator<(const CStr8 &str) const;
bool operator<(PCSTR sz) const;
bool operator<(const char ch) const;
// Tests for less than or equal
bool operator<=(const CDomainName8 &domain) const;
bool operator<=(const CStr8 &str) const;
bool operator<=(PCSTR sz) const;
bool operator<=(const char ch) const;
// Tests for greater than
bool operator>(const CDomainName8 &domain) const;
bool operator>(const CStr8 &str) const;
bool operator>(PCSTR sz) const;
bool operator>(const char ch) const;
// Tests for greater than or equal
bool operator>=(const CDomainName8 &domain) const;
bool operator>=(const CStr8 &str) const;
bool operator>=(PCSTR sz) const;
bool operator>=(const char ch) const;
// Compares the object against the string/character, optionally case insensitive
int Compare(const CDomainName8 &domain, const bool bCaseInsensitive = true) const;
int Compare(const CStr8 &str, const bool bCaseInsensitive = true) const;
int Compare(PCSTR sz, const bool bCaseInsensitive = true) const;
int Compare(const char ch, const bool bCaseInsensitive = true) const;
// Returns whether the string/character is a valid domain name
static bool IsValidDomainName(const CStr8 &strDomainName);
static bool IsValidDomainName(PCSTR szDomainName);
static bool IsValidDomainName(const char chDomainName);
private:
PSTR m_sz = (PSTR)g_szNull8; // String buffer
size_t m_nBufLen = 0; // Length of the buffer in characters
size_t m_nStrLen = 0; // Length of the string in characters
bool Alloc(const size_t nBufLen);
void Dealloc(void);
static PCSTR FindStrPtr(PCSTR sz, const size_t nStrLen, PCSTR szFind, const size_t nFindLen);
static PCSTR FindFirstNotOf(PCSTR sz, const size_t nStrLen, PCSTR szFind, const size_t nFindLen);
};
//#################################################################################################
class CDomainNameW final
{
private:
friend class CDomainName8;
public:
// Constructs an empty object
CDomainNameW(void) = default;
// Copy and move constructors
CDomainNameW(const CDomainNameW &src);
CDomainNameW(CDomainNameW &&src) noexcept;
// Constructs an object set to the string/character
explicit CDomainNameW(const CDomainName8 &domain);
explicit CDomainNameW(const CStrW &str);
explicit CDomainNameW(const CStr8 &str);
explicit CDomainNameW(PCWSTR sz);
explicit CDomainNameW(PCSTR sz);
explicit CDomainNameW(const wchar_t ch);
explicit CDomainNameW(const char ch);
~CDomainNameW(void);
// Returns a pointer to the raw string data
operator PCWSTR(void) const noexcept;
PCWSTR Get(void) const noexcept;
// Returns the length in characters
size_t GetLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes
size_t GetSize(const bool bIncludeNullTerm = false) const noexcept;
// Empties the string
void Empty(void);
// Returns whether the string is empty
bool IsEmpty(void) const noexcept;
// Returns a UTF8 copy of the object
CDomainName8 AsUtf8(void) const;
// Returns a wchar_t copy of the object
CDomainNameW AsWide(void) const;
#ifdef _WIN32
CDomainNameW AsNative(void) const;
#else
CDomainName8 AsNative(void) const;
#endif
// Copy and move assignment operators
CDomainNameW &operator=(const CDomainNameW &src);
CDomainNameW &operator=(CDomainNameW &&src) noexcept;
// Assigns the object to the string/character
CDomainNameW &operator=(const CDomainName8 &domain);
CDomainNameW &operator=(const CStrW &str);
CDomainNameW &operator=(const CStr8 &str);
CDomainNameW &operator=(PCWSTR sz);
CDomainNameW &operator=(PCSTR sz);
CDomainNameW &operator=(const wchar_t ch);
CDomainNameW &operator=(const char ch);
// Assigns the object to the string/character, returns an error code
ERRCODE Assign(const CDomainNameW &domain);
ERRCODE Assign(const CDomainName8 &domain);
ERRCODE Assign(const CStrW &str);
ERRCODE Assign(const CStr8 &str);
ERRCODE Assign(PCWSTR sz);
ERRCODE Assign(PCSTR sz);
ERRCODE Assign(const wchar_t ch);
ERRCODE Assign(const char ch);
friend std::wostream &operator<<(std::wostream &stream, const CDomainNameW &domain);
// Default compare operators are case insensitive
// After all "GOOGLE.COM" and "google.com" are the same site
// For case sensitive compares use the Compare() function
// Tests for equal
bool operator==(const CDomainNameW &domain) const;
bool operator==(const CStrW &str) const;
bool operator==(PCWSTR sz) const;
bool operator==(const wchar_t ch) const;
// Tests for not equal
bool operator!=(const CDomainNameW &domain) const;
bool operator!=(const CStrW &str) const;
bool operator!=(PCWSTR sz) const;
bool operator!=(const wchar_t ch) const;
// Tests for less than
bool operator<(const CDomainNameW &domain) const;
bool operator<(const CStrW &str) const;
bool operator<(PCWSTR sz) const;
bool operator<(const wchar_t ch) const;
// Tests for less than or equal
bool operator<=(const CDomainNameW &domain) const;
bool operator<=(const CStrW &str) const;
bool operator<=(PCWSTR sz) const;
bool operator<=(const wchar_t ch) const;
// Tests for greater than
bool operator>(const CDomainNameW &domain) const;
bool operator>(const CStrW &str) const;
bool operator>(PCWSTR sz) const;
bool operator>(const wchar_t ch) const;
// Tests for greater than or equal
bool operator>=(const CDomainNameW &domain) const;
bool operator>=(const CStrW &str) const;
bool operator>=(PCWSTR sz) const;
bool operator>=(const wchar_t ch) const;
// Compares the object against the string/character, optionally case insensitive
int Compare(const CDomainNameW &domain, const bool bCaseInsensitive = true) const;
int Compare(const CStrW &str, const bool bCaseInsensitive = true) const;
int Compare(PCWSTR sz, const bool bCaseInsensitive = true) const;
int Compare(const wchar_t ch, const bool bCaseInsensitive = true) const;
// Returns whether the string/character is a valid domain name
static bool IsValidDomainName(const CStrW &strDomainName);
static bool IsValidDomainName(PCWSTR szDomainName);
static bool IsValidDomainName(const wchar_t chDomainName);
private:
PWSTR m_sz = (PWSTR)g_szNullW; // String buffer
size_t m_nBufLen = 0; // Length of the buffer in characters
size_t m_nStrLen = 0; // Length of the string in characters
bool Alloc(const size_t nBufLen);
void Dealloc(void);
static PCWSTR FindStrPtr(PCWSTR sz, const size_t nStrLen, PCWSTR szFind, const size_t nFindLen);
static PCWSTR FindFirstNotOf(PCWSTR sz, const size_t nStrLen, PCWSTR szFind, const size_t nFindLen);
};
//#################################################################################################
class CUrlPathSegment8 final
{
private:
friend class CUrlPathSegmentW;
public:
// Constructs an empty object
CUrlPathSegment8(void) = default;
// Copy and move constructors
CUrlPathSegment8(const CUrlPathSegment8 &src);
CUrlPathSegment8(CUrlPathSegment8 &&src) noexcept;
// Constructs an object set to the string/character
explicit CUrlPathSegment8(const CUrlPathSegmentW &path);
explicit CUrlPathSegment8(const CStr8 &str, const bool bAlreadyEscaped = false);
explicit CUrlPathSegment8(const CStrW &str, const bool bAlreadyEscaped = false);
explicit CUrlPathSegment8(PCSTR sz, const bool bAlreadyEscaped = false);
explicit CUrlPathSegment8(PCWSTR sz, const bool bAlreadyEscaped = false);
explicit CUrlPathSegment8(const char ch);
explicit CUrlPathSegment8(const wchar_t ch);
~CUrlPathSegment8(void);
// Returns a pointer to the raw string data
operator PCSTR(void) const noexcept;
PCSTR Get(void) const noexcept;
// Returns the length in characters
size_t GetLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes
size_t GetSize(const bool bIncludeNullTerm = false) const noexcept;
// Empties the string
void Empty(void);
// Returns whether the string is empty
bool IsEmpty(void) const noexcept;
// Returns a UTF8 copy of the object
CUrlPathSegment8 AsUtf8(void) const;
// Returns a wchar_t copy of the object
CUrlPathSegmentW AsWide(void) const;
#ifdef _WIN32
CUrlPathSegmentW AsNative(void) const;
#else
CUrlPathSegment8 AsNative(void) const;
#endif
// Copy and move assignment operators
CUrlPathSegment8 &operator=(const CUrlPathSegment8 &src);
CUrlPathSegment8 &operator=(CUrlPathSegment8 &&src) noexcept;
// Assigns the object to the string/character
CUrlPathSegment8 &operator=(const CUrlPathSegmentW &path);
CUrlPathSegment8 &operator=(const CStr8 &str);
CUrlPathSegment8 &operator=(const CStrW &str);
CUrlPathSegment8 &operator=(PCSTR sz);
CUrlPathSegment8 &operator=(PCWSTR sz);
CUrlPathSegment8 &operator=(const char ch);
CUrlPathSegment8 &operator=(const wchar_t ch);
// Assigns the object to the string/character, returns an error code
ERRCODE Assign(const CUrlPathSegment8 &path);
ERRCODE Assign(const CUrlPathSegmentW &path);
ERRCODE Assign(const CStr8 &str, const bool bAlreadyEscaped = false);
ERRCODE Assign(const CStrW &str, const bool bAlreadyEscaped = false);
ERRCODE Assign(PCSTR sz, const bool bAlreadyEscaped = false);
ERRCODE Assign(PCWSTR sz, const bool bAlreadyEscaped = false);
ERRCODE Assign(const char ch);
ERRCODE Assign(const wchar_t ch);
friend std::ostream &operator<<(std::ostream &stream, const CUrlPathSegment8 &path);
// Default compare operators are case sensitive since
// "Downloads" and "downloads" are different paths
// For case insensitive compares use the Compare() function
// Tests for equal
bool operator==(const CUrlPathSegment8 &path) const;
bool operator==(const CStr8 &str) const;
bool operator==(PCSTR sz) const;
bool operator==(const char ch) const;
// Tests for not equal
bool operator!=(const CUrlPathSegment8 &path) const;
bool operator!=(const CStr8 &str) const;
bool operator!=(PCSTR sz) const;
bool operator!=(const char ch) const;
// Tests for less than
bool operator<(const CUrlPathSegment8 &path) const;
bool operator<(const CStr8 &str) const;
bool operator<(PCSTR sz) const;
bool operator<(const char ch) const;
// Tests for less than or equal
bool operator<=(const CUrlPathSegment8 &path) const;
bool operator<=(const CStr8 &str) const;
bool operator<=(PCSTR sz) const;
bool operator<=(const char ch) const;
// Tests for greater than
bool operator>(const CUrlPathSegment8 &path) const;
bool operator>(const CStr8 &str) const;
bool operator>(PCSTR sz) const;
bool operator>(const char ch) const;
// Tests for greater than or equal
bool operator>=(const CUrlPathSegment8 &path) const;
bool operator>=(const CStr8 &str) const;
bool operator>=(PCSTR sz) const;
bool operator>=(const char ch) const;
// Compares the object against the string/character, optionally case insensitive
int Compare(const CUrlPathSegment8 &path, const bool bCaseInsensitive = false) const;
int Compare(const CStr8 &str, const bool bCaseInsensitive = false) const;
int Compare(PCSTR sz, const bool bCaseInsensitive = false) const;
int Compare(const char ch, const bool bCaseInsensitive = false) const;
// Returns whether the string/character is a valid path segment
static bool IsValidSegment(const CStr8 &strSegment);
static bool IsValidSegment(PCSTR szSegment);
static bool IsValidSegment(const char chSegment) noexcept;
private:
PSTR m_sz = (PSTR)g_szNull8; // String buffer
size_t m_nBufLen = 0; // Length of the buffer in characters
size_t m_nStrLen = 0; // Length of the string in characters
bool Alloc(const size_t nBufLen);
void Dealloc(void);
};
//#################################################################################################
class CUrlPathSegmentW final
{
private:
friend class CUrlPathSegment8;
public:
// Constructs an empty object
CUrlPathSegmentW(void) = default;
// Copy and move constructors
CUrlPathSegmentW(const CUrlPathSegmentW &src);
CUrlPathSegmentW(CUrlPathSegmentW &&src) noexcept;
// Constructs an object set to the string/character
explicit CUrlPathSegmentW(const CUrlPathSegment8 &path);
explicit CUrlPathSegmentW(const CStrW &str, const bool bAlreadyEscaped = false);
explicit CUrlPathSegmentW(const CStr8 &str, const bool bAlreadyEscaped = false);
explicit CUrlPathSegmentW(PCWSTR sz, const bool bAlreadyEscaped = false);
explicit CUrlPathSegmentW(PCSTR sz, const bool bAlreadyEscaped = false);
explicit CUrlPathSegmentW(const wchar_t ch);
explicit CUrlPathSegmentW(const char ch);
~CUrlPathSegmentW(void);
// Returns a pointer to the raw string data
operator PCWSTR(void) const noexcept;
PCWSTR Get(void) const noexcept;
// Returns the length in characters
size_t GetLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes
size_t GetSize(const bool bIncludeNullTerm = false) const noexcept;
// Empties the string
void Empty(void);
// Returns whether the string is empty
bool IsEmpty(void) const noexcept;
// Returns a UTF8 copy of the object
CUrlPathSegment8 AsUtf8(void) const;
// Returns a wchar_t copy of the object
CUrlPathSegmentW AsWide(void) const;
#ifdef _WIN32
CUrlPathSegmentW AsNative(void) const;
#else
CUrlPathSegment8 AsNative(void) const;
#endif
// Copy and move assignment operators
CUrlPathSegmentW &operator=(const CUrlPathSegmentW &src);
CUrlPathSegmentW &operator=(CUrlPathSegmentW &&src) noexcept;
// Assigns the object to the string/character
CUrlPathSegmentW &operator=(const CUrlPathSegment8 &path);
CUrlPathSegmentW &operator=(const CStrW &str);
CUrlPathSegmentW &operator=(const CStr8 &str);
CUrlPathSegmentW &operator=(PCWSTR sz);
CUrlPathSegmentW &operator=(PCSTR sz);
CUrlPathSegmentW &operator=(const wchar_t ch);
CUrlPathSegmentW &operator=(const char ch);
// Assigns the object to the string/character, returns an error code
ERRCODE Assign(const CUrlPathSegmentW &path);
ERRCODE Assign(const CUrlPathSegment8 &path);
ERRCODE Assign(const CStrW &str, const bool bAlreadyEscaped = false);
ERRCODE Assign(const CStr8 &str, const bool bAlreadyEscaped = false);
ERRCODE Assign(PCWSTR sz, const bool bAlreadyEscaped = false);
ERRCODE Assign(PCSTR sz, const bool bAlreadyEscaped = false);
ERRCODE Assign(const wchar_t ch);
ERRCODE Assign(const char ch);
friend std::wostream &operator<<(std::wostream &stream, const CUrlPathSegmentW &path);
// Default compare operators are case sensitive since
// "Downloads" and "downloads" are different paths
// For case insensitive compares use the Compare() function
// Tests for equal
bool operator==(const CUrlPathSegmentW &path) const;
bool operator==(const CStrW &str) const;
bool operator==(PCWSTR sz) const;
bool operator==(const wchar_t ch) const;
// Tests for not equal
bool operator!=(const CUrlPathSegmentW &path) const;
bool operator!=(const CStrW &str) const;
bool operator!=(PCWSTR sz) const;
bool operator!=(const wchar_t ch) const;
// Tests for less than
bool operator<(const CUrlPathSegmentW &path) const;
bool operator<(const CStrW &str) const;
bool operator<(PCWSTR sz) const;
bool operator<(const wchar_t ch) const;
// Tests for less than or equal
bool operator<=(const CUrlPathSegmentW &path) const;
bool operator<=(const CStrW &str) const;
bool operator<=(PCWSTR sz) const;
bool operator<=(const wchar_t ch) const;
// Tests for greater than
bool operator>(const CUrlPathSegmentW &path) const;
bool operator>(const CStrW &str) const;
bool operator>(PCWSTR sz) const;
bool operator>(const wchar_t ch) const;
// Tests for greater than or equal
bool operator>=(const CUrlPathSegmentW &path) const;
bool operator>=(const CStrW &str) const;
bool operator>=(PCWSTR sz) const;
bool operator>=(const wchar_t ch) const;
// Compares the object against the string/character, optionally case insensitive
int Compare(const CUrlPathSegmentW &path, const bool bCaseInsensitive = false) const;
int Compare(const CStrW &str, const bool bCaseInsensitive = false) const;
int Compare(PCWSTR sz, const bool bCaseInsensitive = false) const;
int Compare(const wchar_t ch, const bool bCaseInsensitive = false) const;
// Returns whether the string/character is a valid path segment
static bool IsValidSegment(const CStrW &strSegment);
static bool IsValidSegment(PCWSTR szSegment);
static bool IsValidSegment(const wchar_t chSegment) noexcept;
private:
PWSTR m_sz = (PWSTR)g_szNullW; // String buffer
size_t m_nBufLen = 0; // Length of the buffer in characters
size_t m_nStrLen = 0; // Length of the string in characters
bool Alloc(const size_t nBufLen);
void Dealloc(void);
};
//#################################################################################################
class CUrlParameter8 final
{
private:
friend class CUrlParameterW;
public:
// Constructs an empty object
CUrlParameter8(void) = default;
// Copy and move constructors
CUrlParameter8(const CUrlParameter8 &src);
CUrlParameter8(CUrlParameter8 &&src) noexcept;
// Constructs an object set to the name and value pair
explicit CUrlParameter8(const CUrlParameterW ¶m);
explicit CUrlParameter8(const CStr8 &strName, const CStr8 &strValue = CStr8(g_szNull8), const bool bAlreadyEscaped = false);
explicit CUrlParameter8(const CStrW &strName, const CStrW &strValue = CStrW(g_szNullW), const bool bAlreadyEscaped = false);
explicit CUrlParameter8(PCSTR szName, PCSTR szValue = nullptr, const bool bAlreadyEscaped = false);
explicit CUrlParameter8(PCWSTR szName, PCWSTR szValue = nullptr, const bool bAlreadyEscaped = false);
~CUrlParameter8(void);
// Returns a pointer to the combined string name and value
operator CStr8(void) const;
CStr8 Get(const bool bAlwaysIncludeEqual = false) const;
// Returns the length in characters
size_t GetLength(const bool bAlwaysIncludeEqual = false, const bool bIncludeNullTerm = false) const;
// Returns the size in bytes
size_t GetSize(const bool bAlwaysIncludeEqual = false, const bool bIncludeNullTerm = false) const;
// Returns a pointer to the raw string name
PCSTR GetName(void) const noexcept;
// Returns the length in characters of the name
size_t GetNameLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes of the name
size_t GetNameSize(const bool bIncludeNullTerm = false) const noexcept;
// Returns a pointer to the raw string value
PCSTR GetValue(void) const noexcept;
// Returns the length in characters of the value
size_t GetValueLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes of the value
size_t GetValueSize(const bool bIncludeNullTerm = false) const noexcept;
// Empties the strings
void Empty(void);
// Returns whether the name string is empty
bool IsEmpty(void) const noexcept;
// Returns whether the value string is empty
bool IsValueEmpty(void) const noexcept;
// Returns a UTF8 copy of the object
CUrlParameter8 AsUtf8(void) const;
// Returns a wchar_t copy of the object
CUrlParameterW AsWide(void) const;
#ifdef _WIN32
CUrlParameterW AsNative(void) const;
#else
CUrlParameter8 AsNative(void) const;
#endif
// Copy and move assignment operators
CUrlParameter8 &operator=(const CUrlParameter8 &src);
CUrlParameter8 &operator=(CUrlParameter8 &&src) noexcept;
// Assigns the object to the name and value pair
CUrlParameter8 &operator=(const CUrlParameterW ¶m);
// Assigns the object to the name and value pair, returns an error code
ERRCODE Assign(const CUrlParameter8 ¶m);
ERRCODE Assign(const CUrlParameterW ¶m);
ERRCODE Assign(const CStr8 &strName, const CStr8 &strValue = CStr8(g_szNull8), const bool bAlreadyEscaped = false);
ERRCODE Assign(const CStrW &strName, const CStrW &strValue = CStrW(g_szNullW), const bool bAlreadyEscaped = false);
ERRCODE Assign(PCSTR szName, PCSTR szValue = nullptr, const bool bAlreadyEscaped = false);
ERRCODE Assign(PCWSTR szName, PCWSTR szValue = nullptr, const bool bAlreadyEscaped = false);
// Assigns the object to the name, returns an error code
ERRCODE SetName(const CUrlParameter8 ¶m);
ERRCODE SetName(const CUrlParameterW ¶m);
ERRCODE SetName(const CStr8 &strName, const bool bAlreadyEscaped = false);
ERRCODE SetName(const CStrW &strName, const bool bAlreadyEscaped = false);
ERRCODE SetName(PCSTR szName, const bool bAlreadyEscaped = false);
ERRCODE SetName(PCWSTR szName, const bool bAlreadyEscaped = false);
ERRCODE SetName(const char chName);
ERRCODE SetName(const wchar_t chName);
// Assigns the object to the value, returns an error code
ERRCODE SetValue(const CUrlParameter8 ¶m);
ERRCODE SetValue(const CUrlParameterW ¶m);
ERRCODE SetValue(const CStr8 &strValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(const CStrW &strValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(PCSTR szValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(PCWSTR szValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(const char chValue);
ERRCODE SetValue(const wchar_t chValue);
// Deletes the value
void DeleteValue(void);
friend std::ostream &operator<<(std::ostream &stream, const CUrlParameter8 ¶m);
// Default compare operators are case sensitive since
// "Downloads" and "downloads" are different paths
// For case insensitive compares use the Compare() function
// Tests for equal
bool operator==(const CUrlParameter8 ¶m) const;
// Tests for not equal
bool operator!=(const CUrlParameter8 ¶m) const;
// Tests for less than
bool operator<(const CUrlParameter8 ¶m) const;
// Tests for less than or equal
bool operator<=(const CUrlParameter8 ¶m) const;
// Tests for greater than
bool operator>(const CUrlParameter8 ¶m) const;
// Tests for greater than or equal
bool operator>=(const CUrlParameter8 ¶m) const;
// Compares the object against the string/character, optionally case insensitive
int Compare(const CUrlParameter8 ¶m, const bool bCaseInsensitive = false) const;
int Compare(const CStr8 &strName, const CStr8 &strValue, const bool bCaseInsensitive = false) const;
int Compare(PCSTR szName, PCSTR szValue, const bool bCaseInsensitive = false) const;
// Returns whether the string/character is a valid parameter
static bool IsValidParameter(const CStr8 &strParam);
static bool IsValidParameter(PCSTR szParam);
static bool IsValidParameter(const char chParam);
private:
PSTR m_szName = (PSTR)g_szNull8; // Name string buffer
size_t m_nNameBufLen = 0; // Length of the name buffer in characters
size_t m_nNameStrLen = 0; // Length of the name string in characters
PSTR m_szValue = (PSTR)g_szNull8; // Value string buffer
size_t m_nValueBufLen = 0; // Length of the value buffer in characters
size_t m_nValueStrLen = 0; // Length of the value string in characters
bool AllocName(const size_t nBufLen);
void DeallocName(void);
bool AllocValue(const size_t nBufLen);
void DeallocValue(void);
static PCSTR FindFirstOf(PCSTR sz, const size_t nStrLen, PCSTR szFind, const size_t nFindLen);
};
//#################################################################################################
class CUrlParameterW final
{
private:
friend class CUrlParameter8;
public:
// Constructs an empty object
CUrlParameterW(void) = default;
// Copy and move constructors
CUrlParameterW(const CUrlParameterW &src);
CUrlParameterW(CUrlParameterW &&src) noexcept;
// Constructs an object set to the name and value pair
explicit CUrlParameterW(const CUrlParameter8 ¶m);
explicit CUrlParameterW(const CStrW &strName, const CStrW &strValue = CStrW(g_szNullW), const bool bAlreadyEscaped = false);
explicit CUrlParameterW(const CStr8 &strName, const CStr8 &strValue = CStr8(g_szNull8), const bool bAlreadyEscaped = false);
explicit CUrlParameterW(PCWSTR szName, PCWSTR szValue = nullptr, const bool bAlreadyEscaped = false);
explicit CUrlParameterW(PCSTR szName, PCSTR szValue = nullptr, const bool bAlreadyEscaped = false);
~CUrlParameterW(void);
// Returns a pointer to the combined string name and value
operator CStrW(void) const;
CStrW Get(const bool bAlwaysIncludeEqual = false) const;
// Returns the length in characters
size_t GetLength(const bool bAlwaysIncludeEqual = false, const bool bIncludeNullTerm = false) const;
// Returns the size in bytes
size_t GetSize(const bool bAlwaysIncludeEqual = false, const bool bIncludeNullTerm = false) const;
// Returns a pointer to the raw string name
PCWSTR GetName(void) const noexcept;
// Returns the length in characters of the name
size_t GetNameLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes of the name
size_t GetNameSize(const bool bIncludeNullTerm = false) const noexcept;
// Returns a pointer to the raw string value
PCWSTR GetValue(void) const noexcept;
// Returns the length in characters of the value
size_t GetValueLength(const bool bIncludeNullTerm = false) const noexcept;
// Returns the size in bytes of the value
size_t GetValueSize(const bool bIncludeNullTerm = false) const noexcept;
// Empties the strings
void Empty(void);
// Returns whether the name string is empty
bool IsEmpty(void) const noexcept;
// Returns whether the value string is empty
bool IsValueEmpty(void) const noexcept;
// Returns a UTF8 copy of the object
CUrlParameter8 AsUtf8(void) const;
// Returns a wchar_t copy of the object
CUrlParameterW AsWide(void) const;
#ifdef _WIN32
CUrlParameterW AsNative(void) const;
#else
CUrlParameter8 AsNative(void) const;
#endif
// Copy and move assignment operators
CUrlParameterW &operator=(const CUrlParameterW &src);
CUrlParameterW &operator=(CUrlParameterW &&src) noexcept;
// Assigns the object to the name and value pair
CUrlParameterW &operator=(const CUrlParameter8 ¶m);
// Assigns the object to the name and value pair, returns an error code
ERRCODE Assign(const CUrlParameterW ¶m);
ERRCODE Assign(const CUrlParameter8 ¶m);
ERRCODE Assign(const CStrW &strName, const CStrW &strValue = CStrW(g_szNullW), const bool bAlreadyEscaped = false);
ERRCODE Assign(const CStr8 &strName, const CStr8 &strValue = CStr8(g_szNull8), const bool bAlreadyEscaped = false);
ERRCODE Assign(PCWSTR szName, PCWSTR szValue = nullptr, const bool bAlreadyEscaped = false);
ERRCODE Assign(PCSTR szName, PCSTR szValue = nullptr, const bool bAlreadyEscaped = false);
// Assigns the object to the name, returns an error code
ERRCODE SetName(const CUrlParameterW ¶m);
ERRCODE SetName(const CUrlParameter8 ¶m);
ERRCODE SetName(const CStrW &strName, const bool bAlreadyEscaped = false);
ERRCODE SetName(const CStr8 &strName, const bool bAlreadyEscaped = false);
ERRCODE SetName(PCWSTR szName, const bool bAlreadyEscaped = false);
ERRCODE SetName(PCSTR szName, const bool bAlreadyEscaped = false);
ERRCODE SetName(const wchar_t chName);
ERRCODE SetName(const char chName);
// Assigns the object to the value, returns an error code
ERRCODE SetValue(const CUrlParameterW ¶m);
ERRCODE SetValue(const CUrlParameter8 ¶m);
ERRCODE SetValue(const CStrW &strValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(const CStr8 &strValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(PCWSTR szValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(PCSTR szValue, const bool bAlreadyEscaped = false);
ERRCODE SetValue(const wchar_t chValue);
ERRCODE SetValue(const char chValue);
// Deletes the value
void DeleteValue(void);
friend std::wostream &operator<<(std::wostream &stream, const CUrlParameterW ¶m);
// Default compare operators are case sensitive since
// "Downloads" and "downloads" are different paths
// For case insensitive compares use the Compare() function
// Tests for equal
bool operator==(const CUrlParameterW ¶m) const;
// Tests for not equal
bool operator!=(const CUrlParameterW ¶m) const;
// Tests for less than
bool operator<(const CUrlParameterW ¶m) const;
// Tests for less than or equal
bool operator<=(const CUrlParameterW ¶m) const;
// Tests for greater than
bool operator>(const CUrlParameterW ¶m) const;
// Tests for greater than or equal
bool operator>=(const CUrlParameterW ¶m) const;
// Compares the object against the string/character, optionally case insensitive
int Compare(const CUrlParameterW ¶m, const bool bCaseInsensitive = false) const;
int Compare(const CStrW &strName, const CStrW &strValue, const bool bCaseInsensitive = false) const;
int Compare(PCWSTR szName, PCWSTR szValue, const bool bCaseInsensitive = false) const;
// Returns whether the string/character is a valid parameter
static bool IsValidParameter(const CStrW &strParam);
static bool IsValidParameter(PCWSTR szParam);
static bool IsValidParameter(const wchar_t chParam);
private:
PWSTR m_szName = (PWSTR)g_szNullW; // Name string buffer
size_t m_nNameBufLen = 0; // Length of the name buffer in characters
size_t m_nNameStrLen = 0; // Length of the name string in characters
PWSTR m_szValue = (PWSTR)g_szNullW; // Value string buffer
size_t m_nValueBufLen = 0; // Length of the value buffer in characters
size_t m_nValueStrLen = 0; // Length of the value string in characters
bool AllocName(const size_t nBufLen);
void DeallocName(void);
bool AllocValue(const size_t nBufLen);
void DeallocValue(void);
static PCWSTR FindFirstOf(PCWSTR sz, const size_t nStrLen, PCWSTR szFind, const size_t nFindLen);
};
//#################################################################################################
class CUrl8 final
{
private:
friend class CUrlW;
public:
static const uint32_t no_port;
// Constructs an empty object
CUrl8(void) = default;
// Copy and move constructors
CUrl8(const CUrl8 &src);
CUrl8(CUrl8 &&src) noexcept;
// Constructs an object set to the path/string
explicit CUrl8(const CUrlW &url);
explicit CUrl8(const CDomainName8 &domain);
explicit CUrl8(const CDomainNameW &domain);
explicit CUrl8(const CStr8 &str);
explicit CUrl8(const CStrW &str);
explicit CUrl8(PCSTR sz);
explicit CUrl8(PCWSTR sz);
// Returns a string representing the full path
operator CStr8(void) const;
CStr8 Get(const bool bIncludeScheme = true, const bool bIncludeUsername = true, const bool bIncludePassword = true, const bool bIncludePort = true, const bool bIncludeParams = true, const bool bAlwaysIncludeEqual = false, const bool bIncludeFragment = true) const;
// Returns the length in characters
size_t GetLength(const bool bIncludeNullTerm = false, const bool bIncludeScheme = true, const bool bIncludeUsername = true, const bool bIncludePassword = true, const bool bIncludePort = true, const bool bIncludeParams = true, const bool bAlwaysIncludeEqual = false, const bool bIncludeFragment = true) const;
// Returns the size in bytes
size_t GetSize(const bool bIncludeNullTerm = false, const bool bIncludeScheme = true, const bool bIncludeUsername = true, const bool bIncludePassword = true, const bool bIncludePort = true, const bool bIncludeParams = true, const bool bAlwaysIncludeEqual = false, const bool bIncludeFragment = true) const;
// Copy and move assignment operators
CUrl8 &operator=(const CUrl8 &src);
CUrl8 &operator=(CUrl8 &&src) noexcept;
// Assigns the object to the path/string
CUrl8 &operator=(const CUrlW &url);
CUrl8 &operator=(const CDomainName8 &domain);
CUrl8 &operator=(const CDomainNameW &domain);
CUrl8 &operator=(const CStr8 &str);
CUrl8 &operator=(const CStrW &str);
CUrl8 &operator=(PCSTR sz);
CUrl8 &operator=(PCWSTR sz);
// Assigns the object to the path/string, returns an error code
ERRCODE Assign(const CUrl8 &url);
ERRCODE Assign(const CUrlW &url);
ERRCODE Assign(const CDomainName8 &domain);
ERRCODE Assign(const CDomainNameW &domain);
ERRCODE Assign(const CStr8 &str);
ERRCODE Assign(const CStrW &str);
ERRCODE Assign(PCSTR sz);
ERRCODE Assign(PCWSTR sz);
// Appends the path
CUrl8 &operator+=(const CDomainName8 &domain);
CUrl8 &operator+=(const CDomainNameW &domain);
CUrl8 &operator+=(const CUrlPathSegment8 &path);
CUrl8 &operator+=(const CUrlPathSegmentW &path);
CUrl8 &operator+=(const CUrlParameter8 ¶m);
CUrl8 &operator+=(const CUrlParameterW ¶m);
// Appends the path, returns an error code
ERRCODE Append(const CDomainName8 &domain);
ERRCODE Append(const CDomainNameW &domain);
ERRCODE Append(const CUrlPathSegment8 &path);
ERRCODE Append(const CUrlPathSegmentW &path);
ERRCODE Append(const CUrlParameter8 ¶m);
ERRCODE Append(const CUrlParameterW ¶m);
#ifndef _WIN32
// Returns the concatenation of two paths
friend CUrl8 operator+(const CUrl8 &url, const CUrlPathSegment8 &path);
friend CUrl8 operator+(const CUrl8 &url, const CUrlPathSegmentW &path);
friend CUrl8 operator+(const CUrlW &url, const CUrlPathSegment8 &path);
friend CUrl8 operator+(const CUrlW &url, const CUrlPathSegmentW &path);
friend CUrl8 operator+(const CUrl8 &url, const CUrlParameter8 ¶m);
friend CUrl8 operator+(const CUrl8 &url, const CUrlParameterW ¶m);
friend CUrl8 operator+(const CUrlW &url, const CUrlParameter8 ¶m);
friend CUrl8 operator+(const CUrlW &url, const CUrlParameterW ¶m);
friend CUrl8 operator+(const CDomainName8 &domain, const CUrlPathSegment8 &path);
friend CUrl8 operator+(const CDomainName8 &domain, const CUrlPathSegmentW &path);
friend CUrl8 operator+(const CDomainNameW &domain, const CUrlPathSegment8 &path);
friend CUrl8 operator+(const CDomainNameW &domain, const CUrlPathSegmentW &path);
friend CUrl8 operator+(const CDomainName8 &domain, const CUrlParameter8 ¶m);
friend CUrl8 operator+(const CDomainName8 &domain, const CUrlParameterW ¶m);
friend CUrl8 operator+(const CDomainNameW &domain, const CUrlParameter8 ¶m);
friend CUrl8 operator+(const CDomainNameW &domain, const CUrlParameterW ¶m);
#endif
friend std::ostream &operator<<(std::ostream &stream, const CUrl8 &url);
// Default compare operators are case sensitive since
// "Downloads" and "downloads" are different paths
// For case insensitive compares use the Compare() function
// Tests for equal
bool operator==(const CUrl8 &url) const;
// Tests for not equal
bool operator!=(const CUrl8 &url) const;
// Tests for less than (case sensitive)
bool operator<(const CUrl8 &url) const;
// Tests for less than or equal (case sensitive)
bool operator<=(const CUrl8 &url) const;
// Tests for greater than (case sensitive)
bool operator>(const CUrl8 &url) const;
// Tests for greater than or equal (case sensitive)
bool operator>=(const CUrl8 &url) const;
// Compares the object against the path, optionally case insensitive
bool Compare(const CUrl8 &url, const bool bCaseInsensitive = false) const;
// Empties the path object, freeing the memory
void Empty(void);
// Returns whether the path is empty
bool IsEmpty(void) const noexcept;
// Gets/sets the Url scheme, for example 'https'
const CStr8 &GetScheme(void) const noexcept;
void SetScheme(const CStr8 &strScheme);
// Gets/sets the username embedded in the Url
const CStr8 &GetUsername(void) const noexcept;
void SetUsername(const CStr8 &strUsername);
// Gets/sets the password embedded in the Url
const CStr8 &GetPassword(void) const noexcept;
void SetPassword(const CStr8 &strPassword);
// Gets/sets the domain, for example 'google.com'
const CDomainName8 &GetDomain(void) const noexcept;
void SetDomain(const CDomainName8 &domain);
// Gets/sets the port number, or -1 for no port
uint32_t GetPort(void) const noexcept;
void SetPort(const uint32_t nPort);
// Returns the number of segments in the path
size_t GetSegmentCount(void) const noexcept;
// Returns the segment at a given location, or an empty object if beyond the end of the path
CUrlPathSegment8 GetSegment(const size_t nSegment) const;
// Returns the first segment in the path, or an empty object if the path is empty
CUrlPathSegment8 GetFirstSegment(void) const;
// Returns the last segment in the path, or an empty object if the path is empty
CUrlPathSegment8 GetLastSegment(void) const;
// Removes the leftmost 'nSegmentCount' from the path object
CUrl8 &TrimLeftSegment(const size_t nSegmentCount = 1);
// Removes the rightmost 'nSegmentCount' from the path object
CUrl8 &TrimRightSegment(const size_t nSegmentCount = 1);