TreeNode *getLCA(TreeNode *node1, TreeNode *node2) { if (!node1 || !node2) return NULL; int len1 = getPathLen(node1); int len2 = getPathLen(node2); int cnt; if (len1 > len2) { cnt = len1 - len2; while (cnt--) node1 = node1->parent; } else if (len1 < len2) { cnt = len2 - len1; while (cnt--) node2 = node2->parent; } while (node1 != node2) { node1 = node1->parent; node2 = node2->parent; } return node1; }
char *getPwd(direntry_t *entry) { int size; char *ret; size = getPathLen(entry); ret = malloc(size+1); if(!ret) return 0; sprintPwd(entry, ret); return ret; }
/** * @brief Return the constituent parts of the path. * If we imagine a path as composed of parts separated by slashes, then this function * returns a vector composed of the parts. For example: * * ``` * /x/y/z * ``` * will break out to: * * ``` * path[0] = "" * path[1] = "x" * path[2] = "y" * path[3] = "z" * ``` * * @return A vector of the constituent parts of the path. */ std::vector<std::string> WebServer::HTTPRequest::pathSplit() const { std::istringstream stream(std::string(getPath(), getPathLen())); // I don't know if there's a better istringstream constructor for this std::vector<std::string> ret; std::string pathPart; while (std::getline(stream, pathPart, '/')) { ret.push_back(pathPart); } // Debug for (int i = 0; i < ret.size(); i++) { ESP_LOGD(LOG_TAG, "part[%d]: %s", i, ret[i].c_str()); } return ret; } // pathSplit