This action will force synchronization from 华仔3/cpp-utils, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#ifndef _FORMAT_H#define _FORMAT_H#include <string.h>#include <string>#include <tuple>#include <type_traits>#include <iostream>namespace detail{static void formatArg(char*& buf, int i){int size = sprintf(buf, "%d", i);buf += size;}static void formatArg(char*& buf, long i){int size = sprintf(buf, "%ld", i);buf += size;}static void formatArg(char*& buf, long long i){int size = sprintf(buf, "%lld", i);buf += size;}static void formatArg(char*& buf, double i){int size = sprintf(buf, "%.6f", i);buf += size;}static void formatArg(char*& buf, const char* p){int len = strlen(p);memcpy(buf, p, len);buf += len;}static void formatArg(char*& buf, const std::string& str){memcpy(buf, str.c_str(), str.size());buf += str.size();}template<std::size_t i, typename Tuple>static typename std::enable_if<(i == std::tuple_size<Tuple>::value)>::typegetArgByIndex(std::size_t, Tuple&, char*&){throw std::invalid_argument("Arg index out of range");}template<std::size_t i = 0, typename Tuple>static typename std::enable_if<(i < std::tuple_size<Tuple>::value)>::typegetArgByIndex(std::size_t index, Tuple& tp, char*& p){if (i == index){formatArg(p, std::get<i>(tp));}else{getArgByIndex<i + 1>(index, tp, p);}}static int getIndex(char*& p){char temp[3] = {'0円'};int i = 0;while (*p != '}' && *p != '0円'){if (i >= 2){throw std::invalid_argument("Index is out of range");}if (std::isdigit(*p)){// push digittemp[i++] = *p;char next = *(p + 1);if (std::isdigit(next)){temp[i++] = next;p += 2;continue;}// validate argif (!std::isspace(next) && next != '}'){throw std::invalid_argument("Invaild argument");}}++p;}return i == 0 ? -1 : std::atoi(temp);}}template<typename... Args>static std::string format(char* str, Args... args){char arr[4096] = {'0円'};char* buf = arr;auto tp = std::tuple<Args...>(args...);char* p = str;char* original = p;int last = 0;while (true){if (*p == '{'){// copy context before {last = p - original;memcpy(buf, original, last);buf += last;// format argsint index = detail::getIndex(p);if (index >= 0){detail::getArgByIndex<0>(index, tp, buf);}// skip }original = p + 1;}else if (*p == '0円'){last = p - original;memcpy(buf, original, last);break;}++p;}return arr;}#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。