Returns a part of the url or null if it doesn't exist
@param int $part_number 1 indexed url part number e.g /a/b a is part 1 and b is part 2
@return string|null the url part
512329
public function getUrlPart($part_number)
	{
		// Split the url into an array by slashes
		$request_uri = array_filter(explode('/', $this->_request_uri), function($part) {
			return !empty($part);
		});

		return !empty($request_uri[$part_number]) ? $request_uri[$part_number] : null;
	}
1268337
protected static function format_get($url_parts, $data) {
		if (!empty($data)) {
			if (empty($url_parts['query']))
				$url_parts['query'] = '';

			$url_parts['query'] .= '&' . http_build_query($data, null, '&');
			$url_parts['query'] = trim($url_parts['query'], '&');
		}
		if (isset($url_parts['path'])) {
			if (isset($url_parts['query'])) {
				$get = "$url_parts[path]?$url_parts[query]";
			}
			else {
				$get = $url_parts['path'];
			}
		}
		else {
			$get = '/';
		}
		return $get;
	}
508272
public function segment($index) {
		if (isset($this->segments[$index])) {
			return $this->segments[$index];
		}

		return null;
	}
1324184
public String getSubstring(Part part) {
        int index=part.index;
        return msg.substring(index, index+part.length);
    }
564153
public function getPart($num)
    {
        --$num;
        if (!isset($this->_partPos[$num])) {
            /**
             * @see Zend_Mail_Exception
             */
            // require_once 'Zend/Mail/Exception.php';
            throw new Zend_Mail_Exception('part not found');
        }

        return new self(array('file' => $this->_fh, 'startPos' => $this->_partPos[$num][0],
                              'endPos' => $this->_partPos[$num][1]));
    }
533639
public static function getURI() {
        if (isset($_SERVER ['REQUEST_URI'])) {
            if (WWWROOT_DIR != '/') {
                $uri = substr($_SERVER ['REQUEST_URI'], strlen(WWWROOT_DIR) - 1);
            } else {
                $uri = $_SERVER ['REQUEST_URI'];
            }

            return $uri;
        }

        return null;
    }
396361
public function getPart($partNumber, $encoding)
    {
        $data = imap_fetchbody($this->conn, $this->messageNumber, $partNumber);
        switch ($encoding) {
            case 0:
                return $data; // 7BIT
            case 1:
                return $data; // 8BIT
            case 2:
                return $data; // BINARY
            case 3:
                return base64_decode($data); // BASE64
            case 4:
                return quoted_printable_decode($data); // QUOTED_PRINTABLE
            case 5:
                return $data; // OTHER
        }
    }
813681
public static function assembleUrl ($parts) {
    $url = '';
    if (isset($parts['scheme'])) {
      $url .= "{$parts['scheme']}:";
    }
    $url .= '//';
    if (isset($parts['user'])) {
      $url .= $parts['user'];
      if (isset($parts['password'])) {
        $url .= ":{$parts['password']}";
      }
      $url .= '@';
    }
    if (isset($parts['host'])) {
      $url .= $parts['host'];
    }
    if (isset($parts['port'])) {
      $url .= ":{$parts['port']}";
    }
    if (isset($parts['path'])) {
      $url .= $parts['path'];
    }
    if (isset($parts['query'])) {
      $url .= "?{$parts['query']}";
    }
    if (isset($parts['fragment'])) {
      $url .= "#{$parts['fragment']}";
    }
    return $url;
  }
1200508
final protected function doGetContent(string $partNumber): string
    {
        $return = \imap_fetchbody(
            $this->resource->getStream(),
            $this->getNumber(),
            $partNumber,
            \FT_UID | \FT_PEEK
        );

        if (false === $return) {
            throw new ImapFetchbodyException('imap_fetchbody failed');
        }

        return $return;
    }
482301
function isSearchPartIncomplete( $part )
    {
        switch ( $part['subtype'] )
        {
            case 'fulltext':
            {
                if ( !isset( $part['value'] ) || $part['value'] == '' )
                    return true;
            }
            break;

            case 'patterntext':
            {
                if ( !isset( $part['value'] ) || $part['value'] == '' )
                    return true;
            }
            break;

            case 'integer':
            {
                if ( !isset( $part['value'] ) || $part['value'] == '' )
                    return true;
            }
            break;

            case 'integers':
            {
                if ( !isset( $part['values'] ) || count( $part['values'] ) == 0 )
                    return true;
            }
            break;

            case 'byrange':
            {
                if ( !isset( $part['from'] ) || $part['from'] == '' ||
                     !isset( $part['to'] ) || $part['to'] == '' )
                    return true;
            }
            break;

            case 'byidentifier':
            {
                if ( !isset( $part['value'] ) || $part['value'] == '' )
                    return true;
            }
            break;

            case 'byidentifierrange':
            {
                if ( !isset( $part['from'] ) || $part['from'] == '' ||
                     !isset( $part['to'] ) || $part['to'] == '' )
                    return true;
            }
            break;

            case 'integersbyidentifier':
            {
                if ( !isset( $part['values'] ) || count( $part['values'] ) == 0 )
                    return true;
            }
            break;

            case 'byarea':
            {
                if ( !isset( $part['from'] ) || $part['from'] == '' ||
                     !isset( $part['to'] ) || $part['to'] == '' ||
                     !isset( $part['minvalue'] ) || $part['minvalue'] == '' ||
                     !isset( $part['maxvalue'] ) || $part['maxvalue'] == '' )
                {
                    return true;
                }
            }
        }
        return false;
    }
454760
public static function buildUrl($parts)
    {
        $url = '';

        if (isset($parts['scheme'])) {
            $url .= $parts['scheme'].'://';
        }

        if (isset($parts['user'])) {
            if (isset($parts['pass'])) {
                $url .= $parts['user'].':'.$parts['pass'].'@';
            } else {
                $url .= $parts['user'].'@';
            }
        }

        if (isset($parts['host'])) {
            $url .= $parts['host'];
        }

        if (isset($parts['port'])) {
            $url .= ':'.$parts['port'];
        }

        if (isset($parts['path'])) {
            $url .= $parts['path'];
        }

        if (isset($parts['query'])) {
            $url .= '?'.$parts['query'];
        }

        if (isset($parts['fragment'])) {
            $url .= '#'.$parts['fragment'];
        }

        return $url;
    }
567108
public function nextPageUrl()
	{
		if ( $this->lastPage() > $this->currentPage() )
			return $this->url( $this->currentPage() + 1 );

		return null;
	}
88085
public function getPart($key)
    {
        foreach ($this->parts as $part) {
            if ($part->getKey() === $key) {
                return $part;
            }
        }
        
        return false;
    }
1123354
def last_part_number(self):
        """"""
        return int(self.size / self.chunk_size) \
            if self.size % self.chunk_size else \
            int(self.size / self.chunk_size) - 1
618524
public static String urlEncode(String part) {
		try {
			return URLEncoder.encode(part, Charsets.UTF_8_NAME);
		} catch (UnsupportedEncodingException ignored) { // NOSONAR
			// this exception is only for detecting and handling invalid inputs
			return null;
		}
	}
940683
public function get_url() {
        global $CFG;

        // We keep compatibility with 2.7 and 2.8 other['coursesectionid'].
        $sectionnumber = null;
        if (isset($this->other['coursesectionnumber'])) {
            $sectionnumber = $this->other['coursesectionnumber'];
        } else if (isset($this->other['coursesectionid'])) {
            $sectionnumber = $this->other['coursesectionid'];
        }
        require_once($CFG->dirroot . '/course/lib.php');
        try {
            return course_get_url($this->courseid, $sectionnumber);
        } catch (\Exception $e) {
            return null;
        }
    }
999296
public function getBody($part = null)
    {
        $data = $this->getPartData($part);
        $start = $data['starting-pos-body'];
        $end = $data['ending-pos-body'];

        return substr($this->text, $start, $end - $start);
    }