static int URI_FUNC()

in cpp/src/arrow/vendored/uriparser/UriShorten.c [126:292]


static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
		const URI_TYPE(Uri) * absSource,
		const URI_TYPE(Uri) * absBase,
		UriBool domainRootMode, UriMemoryManager * memory) {
	if (dest == NULL) {
		return URI_ERROR_NULL;
	}
	URI_FUNC(ResetUri)(dest);

	if ((absSource == NULL) || (absBase == NULL)) {
		return URI_ERROR_NULL;
	}

	/* absBase absolute? */
	if (absBase->scheme.first == NULL) {
		return URI_ERROR_REMOVEBASE_REL_BASE;
	}

	/* absSource absolute? */
	if (absSource->scheme.first == NULL) {
		return URI_ERROR_REMOVEBASE_REL_SOURCE;
	}

	/* [01/50]	if (A.scheme != Base.scheme) then */
				if (URI_FUNC(CompareRange)(&absSource->scheme, &absBase->scheme)) {
	/* [02/50]	   T.scheme    = A.scheme; */
					dest->scheme = absSource->scheme;
	/* [03/50]	   T.authority = A.authority; */
					if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
						return URI_ERROR_MALLOC;
					}
	/* [04/50]	   T.path      = A.path; */
					if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
						return URI_ERROR_MALLOC;
					}
	/* [05/50]	else */
				} else {
	/* [06/50]	   undef(T.scheme); */
					/* NOOP */
	/* [07/50]	   if (A.authority != Base.authority) then */
					if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) {
	/* [08/50]	      T.authority = A.authority; */
						if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
							return URI_ERROR_MALLOC;
						}
	/* [09/50]	      T.path      = A.path; */
						if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
							return URI_ERROR_MALLOC;
						}
	/* [10/50]	   else */
					} else {
	/* [11/50]	      if domainRootMode then */
						if (domainRootMode == URI_TRUE) {
	/* [12/50]	         undef(T.authority); */
							/* NOOP */
	/* [13/50]	         if (first(A.path) == "") then */
							/* GROUPED */
	/* [14/50]	            T.path   = "/." + A.path; */
								/* GROUPED */
	/* [15/50]	         else */
								/* GROUPED */
	/* [16/50]	            T.path   = A.path; */
								/* GROUPED */
	/* [17/50]	         endif; */
							if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
								return URI_ERROR_MALLOC;
							}
							dest->absolutePath = URI_TRUE;

							if (!URI_FUNC(FixAmbiguity)(dest, memory)) {
								return URI_ERROR_MALLOC;
							}
	/* [18/50]	      else */
						} else {
							const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead;
							const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead;
	/* [19/50]	         bool pathNaked = true; */
							UriBool pathNaked = URI_TRUE;
	/* [20/50]	         undef(last(Base.path)); */
							/* NOOP */
	/* [21/50]	         T.path = ""; */
							dest->absolutePath = URI_FALSE;
	/* [22/50]	         while (first(A.path) == first(Base.path)) do */
							while ((sourceSeg != NULL) && (baseSeg != NULL)
									&& !URI_FUNC(CompareRange)(&sourceSeg->text, &baseSeg->text)
									&& !((sourceSeg->text.first == sourceSeg->text.afterLast)
										&& ((sourceSeg->next == NULL) != (baseSeg->next == NULL)))) {
	/* [23/50]	            A.path++; */
								sourceSeg = sourceSeg->next;
	/* [24/50]	            Base.path++; */
								baseSeg = baseSeg->next;
	/* [25/50]	         endwhile; */
							}
	/* [26/50]	         while defined(first(Base.path)) do */
							while ((baseSeg != NULL) && (baseSeg->next != NULL)) {
	/* [27/50]	            Base.path++; */
								baseSeg = baseSeg->next;
	/* [28/50]	            T.path += "../"; */
								if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent),
										URI_FUNC(ConstParent) + 2, memory)) {
									return URI_ERROR_MALLOC;
								}
	/* [29/50]	            pathNaked = false; */
								pathNaked = URI_FALSE;
	/* [30/50]	         endwhile; */
							}
	/* [31/50]	         while defined(first(A.path)) do */
							while (sourceSeg != NULL) {
	/* [32/50]	            if pathNaked then */
								if (pathNaked == URI_TRUE) {
	/* [33/50]	               if (first(A.path) contains ":") then */
									UriBool containsColon = URI_FALSE;
									const URI_CHAR * ch = sourceSeg->text.first;
									for (; ch < sourceSeg->text.afterLast; ch++) {
										if (*ch == _UT(':')) {
											containsColon = URI_TRUE;
											break;
										}
									}

									if (containsColon) {
	/* [34/50]	                  T.path += "./"; */
										if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstPwd),
												URI_FUNC(ConstPwd) + 1, memory)) {
											return URI_ERROR_MALLOC;
										}
	/* [35/50]	               elseif (first(A.path) == "") then */
									} else if (sourceSeg->text.first == sourceSeg->text.afterLast) {
	/* [36/50]	                  T.path += "/."; */
										if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstPwd),
												URI_FUNC(ConstPwd) + 1, memory)) {
											return URI_ERROR_MALLOC;
										}
	/* [37/50]	               endif; */
									}
	/* [38/50]	            endif; */
								}
	/* [39/50]	            T.path += first(A.path); */
								if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first,
										sourceSeg->text.afterLast, memory)) {
									return URI_ERROR_MALLOC;
								}
	/* [40/50]	            pathNaked = false; */
								pathNaked = URI_FALSE;
	/* [41/50]	            A.path++; */
								sourceSeg = sourceSeg->next;
	/* [42/50]	            if defined(first(A.path)) then */
								/* NOOP */
	/* [43/50]	               T.path += + "/"; */
								/* NOOP */
	/* [44/50]	            endif; */
								/* NOOP */
	/* [45/50]	         endwhile; */
							}
	/* [46/50]	      endif; */
						}
	/* [47/50]	   endif; */
					}
	/* [48/50]	endif; */
				}
	/* [49/50]	T.query     = A.query; */
				dest->query = absSource->query;
	/* [50/50]	T.fragment  = A.fragment; */
				dest->fragment = absSource->fragment;

	return URI_SUCCESS;
}