FastLED 3.9.15
Loading...
Searching...
No Matches

◆ parse()

void fl::url::parse ( )
inlineprivate

Definition at line 121 of file url.h.

121 {
122 if (mUrl.empty()) {
123 return;
124 }
125
126 fl::string_view src(mUrl.c_str(), mUrl.size());
127 fl::size pos = 0;
128
129 // 1. Scheme — look for "://"
130 fl::size sep = src.find("://");
131 if (sep == fl::string_view::npos) {
132 // No scheme found — assume https:// and retry
133 mUrl = fl::string("https://") + mUrl;
134 mRepaired = true;
135 src = fl::string_view(mUrl.c_str(), mUrl.size());
136 sep = src.find("://");
137 }
138 mScheme = makeSpan(0, sep);
139 pos = sep + 3; // skip past "://"
140
141 // 2. Authority — everything up to first '/', '?', or '#'
142 fl::size authStart = pos;
143 fl::size authEnd = src.size();
144 for (fl::size i = pos; i < src.size(); ++i) {
145 char c = src[i];
146 if (c == '/' || c == '?' || c == '#') {
147 authEnd = i;
148 break;
149 }
150 }
151 mAuthority = makeSpan(authStart, authEnd - authStart);
152
153 // 3. Parse authority into userinfo, host, port
154 parseAuthority(src.substr(authStart, authEnd - authStart), authStart);
155
156 pos = authEnd;
157
158 // 4. Path — up to '?' or '#'
159 if (pos < src.size() && src[pos] == '/') {
160 fl::size pathStart = pos;
161 fl::size pathEnd = src.size();
162 for (fl::size i = pos; i < src.size(); ++i) {
163 if (src[i] == '?' || src[i] == '#') {
164 pathEnd = i;
165 break;
166 }
167 }
168 mPath = makeSpan(pathStart, pathEnd - pathStart);
169 pos = pathEnd;
170 }
171
172 // 5. Query — after '?' up to '#'
173 if (pos < src.size() && src[pos] == '?') {
174 ++pos; // skip '?'
175 fl::size qStart = pos;
176 fl::size qEnd = src.size();
177 fl::size hashPos = src.find('#', pos);
178 if (hashPos != fl::string_view::npos) {
179 qEnd = hashPos;
180 }
181 mQuery = makeSpan(qStart, qEnd - qStart);
182 pos = qEnd;
183 }
184
185 // 6. Fragment — after '#'
186 if (pos < src.size() && src[pos] == '#') {
187 ++pos; // skip '#'
188 mFragment = makeSpan(pos, src.size() - pos);
189 }
190
191 mValid = true;
192 }
uint8_t pos
Definition Blur.ino:11
static constexpr fl::size npos
Definition string_view.h:35
Span mScheme
Definition url.h:236
Span mQuery
Definition url.h:241
Span mAuthority
Definition url.h:243
bool mRepaired
Definition url.h:235
Span mFragment
Definition url.h:242
static Span makeSpan(fl::size off, fl::size len) FL_NOEXCEPT
Definition url.h:103
void parseAuthority(fl::string_view auth, fl::size baseOff) FL_NOEXCEPT
Definition url.h:194
Span mPath
Definition url.h:240
bool mValid
Definition url.h:234
fl::string mUrl
Definition url.h:233

References fl::string_view::find(), FL_NOEXCEPT, makeSpan(), mAuthority, mFragment, mPath, mQuery, mRepaired, mScheme, mUrl, mValid, fl::string_view::npos, parseAuthority(), pos, fl::string_view::size(), and fl::string_view::substr().

Referenced by url(), url(), and url().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: