CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/File/AndroidContentURI.h
Views: 1401
#pragma once12#include <string>34#include "Common/StringUtils.h"5#include "Common/Net/URL.h"6#include "Common/Log.h"78// Utility to deal with Android storage URIs of the forms:9// content://com.android.externalstorage.documents/tree/primary%3APSP%20ISO10// content://com.android.externalstorage.documents/tree/primary%3APSP%20ISO/document/primary%3APSP%20ISO1112// This file compiles on all platforms, to reduce the need for ifdefs.1314// I am not 100% sure it's OK to rely on the internal format of file content URIs.15// On the other hand, I'm sure tons of apps would break if these changed, so I think we can16// consider them pretty stable. Additionally, the official Document library just manipulates the URIs17// in similar ways...18class AndroidContentURI {19private:20std::string provider;21std::string root;22std::string file;23public:24AndroidContentURI() {}25explicit AndroidContentURI(std::string_view path) {26Parse(path);27}2829bool Parse(std::string_view path);3031AndroidContentURI WithRootFilePath(const std::string &filePath);32AndroidContentURI WithComponent(std::string_view filePath);33AndroidContentURI WithExtraExtension(std::string_view extension); // The ext string contains the dot.34AndroidContentURI WithReplacedExtension(const std::string &oldExtension, const std::string &newExtension) const;35AndroidContentURI WithReplacedExtension(const std::string &newExtension) const;3637bool CanNavigateUp() const;3839// Only goes downwards in hierarchies. No ".." will ever be generated.40bool ComputePathTo(const AndroidContentURI &other, std::string &path) const;4142std::string GetFileExtension() const;43std::string GetLastPart() const;4445bool NavigateUp();4647bool TreeContains(const AndroidContentURI &fileURI) {48if (root.empty()) {49return false;50}51return startsWith(fileURI.file, root);52}5354std::string ToString() const;5556// Never store the output of this, only show it to the user.57std::string ToVisualString() const {58return file;59}6061const std::string &FilePath() const {62return file;63}6465const std::string &RootPath() const {66return root.empty() ? file : root;67}6869const std::string &Provider() const {70return provider;71}7273bool IsTreeURI() const {74return !root.empty();75}76};777879