开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
开源项目 > 程序开发 > 编程语言/脚本语言 &&
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
13 Star 69 Fork 22

johnsonyl/cpps

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
v1.0.2
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
v1.0.2
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
v1.0.2
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
cpps
/
src
/
cpps_string.cpp
cpps
/
src
/
cpps_string.cpp
cpps_string.cpp 24.06 KB
一键复制 编辑 原始数据 按行查看 历史
johnsonyl 提交于 2023年12月04日 16:55 +08:00 . 增加一些常用接口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
#include "cpps/cpps.h"
namespace cpps
{
size_t formatcheck(C* c, std::string& fmt, size_t j, size_t i, std::string& take, cpps_value& v);
cpps_integer cpps_string_len(cpps_value v)
{
if (v.tt == CPPS_TSTRING) {
cpps_cppsclassvar *cppsclassvar = (cpps_cppsclassvar *)v.value.domain;
std::string *tmpStr = (std::string *)cppsclassvar->getclsptr();
return tmpStr->size();
}
return 0;
}
cpps_integer cpps_string_strlen(cpps_value v)
{
if (v.tt == CPPS_TSTRING) {
std::string* tmpStr = cpps_get_string(v);
return strlen(tmpStr->c_str());
}
return 0;
}
cpps_integer cpps_string_find(cpps_value v, std::string v2,cpps_integer off)
{
if (v.tt != CPPS_TSTRING) return std::string::npos;
std::string* tmpStr = cpps_get_string(v);
return tmpStr->find(v2, size_t(off));
}
cpps_integer cpps_string_rfind(cpps_value v, std::string v2, cpps_integer off)
{
if (v.tt != CPPS_TSTRING) return std::string::npos;
std::string* tmpStr = cpps_get_string(v);
return tmpStr->rfind(v2, size_t(off));
}
void cpps_string_copyto(cpps_value src, cpps_value tar, cpps_value off,cpps_value len ) {
if (src.tt != CPPS_TSTRING) return ;
if (tar.tt != CPPS_TSTRING) return ;
size_t noff = 0;
size_t count = std::string::npos;
noff = cpps_isint(off) ? (size_t)cpps_to_integer(off) : noff;
count = cpps_isint(len) ? (size_t)cpps_to_integer(len) : count;
std::string* srcstr = cpps_get_string(src);
std::string* tarstr = cpps_get_string(tar);
*tarstr = srcstr->substr(noff, count);
}
void cpps_string_clear(cpps_value v) {
if (v.tt != CPPS_TSTRING) return ;
cpps_cppsclassvar* cppsclassvar = (cpps_cppsclassvar*)v.value.domain;
std::string* tmpStr = (std::string*)cppsclassvar->getclsptr();
tmpStr->clear();
}
cpps_value cpps_string_replace(cpps_value v, std::string v2, std::string v3)
{
if (v.tt != CPPS_TSTRING) return nil;
std::string::size_type pos = 0;
std::string* tmpStr = cpps_get_string(v);
while ((pos = tmpStr->find(v2, pos)) != std::string::npos)
{
tmpStr->replace(pos, v2.length(), v3);
pos += v3.length();
}
return v;
}
cpps_value cpps_string_cut(C* c, cpps_value v, cpps_integer count) {
if (v.tt != CPPS_TSTRING) return nil;
cpps_vector* vec;
cpps_value ret;
newclass<cpps_vector>(c, &vec,&ret);
cpps_cppsclassvar* cppsclassvar = (cpps_cppsclassvar*)v.value.domain;
std::string* tmpStr = (std::string*)cppsclassvar->getclsptr();
size_t ncount = (size_t)count;
size_t FileSize = tmpStr->size();
size_t pos1 = 0;
for (size_t j = 0; j < FileSize / ncount + 1; j++)
{
size_t res = FileSize - pos1 < ncount ? FileSize - pos1 : ncount;
if (res != 0)
{
std::string *s;
cpps_value sv;
newclass<std::string>(c, &s,&sv);
s->append(tmpStr->c_str() + pos1, res);
vec->push_back(sv);
pos1 += res;
}
}
return ret;
}
void cpps_string_real_split(std::vector<std::string>&vec, std::string &v, std::string v2,cpps_integer count)
{
size_t ncount = (size_t)count;
if (v.empty()) return;
const char *a = v.c_str(); const char *b;
while (true)
{
b = strstr(a, v2.c_str());
if (!b) b = a + strlen(a);
std::string s;
s.append(a, strlen(a) - strlen(b));
vec.push_back(s);
if (count != -1 && vec.size() >= ncount) break;
//如果到了结尾那就出去吧。
if (strlen(b) == 0 || strlen(b) == 1) break;
else a = b + v2.size();
}
}
cpps_value cpps_string_split(C *c, cpps_value v, std::string v2,cpps_value count)
{
if (v.tt != CPPS_TSTRING) return nil;
cpps_integer ncount = -1;
if (cpps_isint(count)) ncount = count.value.integer;
cpps_vector *vec;
cpps_value ret;
newclass<cpps_vector>(c, &vec,&ret);
std::string* tmpStr = cpps_get_string(v);
if (tmpStr->empty()) return ret;
const char *a = tmpStr->c_str(); const char *b;
while (true)
{
b = strstr(a, v2.c_str());
if (!b) b = a + strlen(a);
std::string s;
s.append(a, strlen(a) - strlen(b));
vec->push_back(cpps_value(c,s));
if (ncount != -1 && vec->size() >= ncount) break;
//如果到了结尾那就出去吧。
if (strlen(b) == 0 || strlen(b) == 1) break;
else a = b + v2.size();
}
return ret;
}
std::string cpps_string_real_strcut(std::string &v, std::string v2, std::string v3)
{
const char * strtmp1 = strstr(v.c_str(), v2.c_str());
if (!strtmp1) return "";
const char * strtmp2 = strstr(strtmp1 + v2.size(), v3.c_str());
if (!strtmp2) return "";
std::string out;
out.append(strtmp1 + v2.size(), strtmp2 - strtmp1 - v2.size());
return out;
}
std::string cpps_string_strcut(cpps_value v, std::string v2, std::string v3)
{
if (v.tt != CPPS_TSTRING) return "";
cpps_cppsclassvar* cppsclassvar = (cpps_cppsclassvar*)v.value.domain;
std::string* tmpStr = (std::string*)cppsclassvar->getclsptr();
const char* strtmp1 = strstr(tmpStr->c_str(), v2.c_str());
if (!strtmp1) return "";
const char* strtmp2 = strstr(strtmp1 + v2.size(), v3.c_str());
if (!strtmp2) return "";
std::string out;
out.append(strtmp1 + v2.size(), strtmp2 - strtmp1 - v2.size());
return out;
}
cpps_value cpps_string_strcuts(C *c, cpps_value old, std::string start, std::string end)
{
if (old.tt != CPPS_TSTRING) return nil;
cpps_vector *vec;
cpps_value ret;
newclass<cpps_vector>(c, &vec,&ret);
std::string* tmpStr = cpps_get_string(old);
const char *begin = tmpStr->c_str();
while (true)
{
const char * strtmp1 = strstr(begin, start.c_str());
if (!strtmp1) return ret;
const char * strtmp2 = strstr(strtmp1 + start.size(), end.c_str());
if (!strtmp2) return ret;
std::string out;
out.append(strtmp1 + start.size(), strtmp2 - strtmp1 - start.size());
vec->push_back(cpps_value(c,out));
begin = strtmp2 + end.size();
}
return ret;
}
bool cpps_string_empty(cpps_value v)
{
if (v.tt != CPPS_TSTRING) return true;
std::string* tmpStr = cpps_get_string(v);
return tmpStr->empty();
}
std::string cpps_string_sub(cpps_value v,cpps_integer pos,cpps_value nn)
{
size_t n = std::string::npos;
n = cpps_isint(nn) ? (size_t)cpps_to_integer(nn) : n;
if (v.tt != CPPS_TSTRING) return "";
std::string* tmpStr = cpps_get_string(v);
size_t tmpn = (size_t)n;
if (tmpStr->size() <= size_t(pos)) return "";
if (tmpStr->size() <= size_t(pos + tmpn) && tmpn != std::string::npos) tmpn = std::string::npos;
return tmpStr->substr((size_t) pos, (size_t)n);
}
cpps_integer cpps_string_npos()
{
return std::string::npos;
}
std::string cpps_string_at(cpps_value v,cpps_integer pos)
{
if (v.tt != CPPS_TSTRING) return "";
std::string* tmpStr = cpps_get_string(v);
return tmpStr->substr(size_t(pos), 1);
}
std::string cpps_string_format(C*c,cpps::cpps_value args, ...)
{
cpps::object _vct = cpps::object(args);
cpps::object::vector vct = cpps::object::vector(_vct);
std::string fmt = vct[0].tostring();
size_t idx = 1;
std::string take;
for (size_t i = 0; i < fmt.size(); i++)
{
if (fmt[i] == '%')
{
if (fmt[i + 1] == '%')
{
fmt.replace(i, 2, "%");
continue;
}
take = "";
for (size_t j = i; j < fmt.size(); j++)
{
take.push_back(fmt[j]);
size_t newsize = formatcheck(c,fmt, j, i, take, vct[(cpps_integer)idx].realval());
if (newsize != 0)
{
idx++;
i += newsize - 1;
break;
}
}
}
}
return fmt;
}
void cpps_string_real_tolower(std::string& s) {
for (size_t i = 0;i < s.size(); ++i){
s[i] = (char)tolower((int)s[i]);
}
}
cpps_value cpps_string_lower(cpps_value v)
{
if (v.tt == CPPS_TSTRINGV) {
char& strv = *(v.value.strv);
return (cpps_integer)tolower(strv);
}
if (v.tt == CPPS_TINTEGER || v.tt == CPPS_TUINTEGER) {
return (cpps_integer)tolower((int)cpps_to_integer(v));
}
if (v.tt != CPPS_TSTRING) return nil;
std::string* tmpStr = cpps_get_string(v);
cpps_string_real_tolower(*tmpStr);
return v;
}
void cpps_string_real_toupper(std::string& s) {
for (size_t i = 0; i < s.size(); ++i) {
s[i] = (char)toupper((int)s[i]);
}
}
cpps_value cpps_string_upper(cpps_value v)
{
if (v.tt == CPPS_TSTRINGV) {
char& strv = *(v.value.strv);
return (cpps_integer)toupper(strv);
}
if (v.tt == CPPS_TINTEGER || v.tt == CPPS_TUINTEGER) {
return (cpps_integer)toupper((int)cpps_to_integer(v));
}
if (v.tt != CPPS_TSTRING) return nil;
std::string* tmpStr = cpps_get_string(v);
cpps_string_real_toupper(*tmpStr);
return v;
}
void cpps_string_pop_back(cpps_value s, cpps_integer c) {
if (s.tt != CPPS_TSTRING) return;
cpps_cppsclassvar* cppsclassvar = (cpps_cppsclassvar*)s.value.domain;
std::string* tmpStr = (std::string*)cppsclassvar->getclsptr();
for (cpps_integer i = 0; i < c; i++) {
tmpStr->pop_back();
}
}
bool cpps_string_startswith(cpps_value s,std::string end) {
if (s.tt != CPPS_TSTRING) return false;
cpps_cppsclassvar* cppsclassvar = (cpps_cppsclassvar*)s.value.domain;
std::string* tmpStr = (std::string*)cppsclassvar->getclsptr();
size_t pos = tmpStr->find(end);
if (pos == std::string::npos) return false;
if (pos == 0) return true;
return false;
}
bool cpps_string_endswith(cpps_value s, std::string end) {
if (s.tt != CPPS_TSTRING) return false;
cpps_cppsclassvar* cppsclassvar = (cpps_cppsclassvar*)s.value.domain;
std::string* tmpStr = (std::string*)cppsclassvar->getclsptr();
size_t pos = tmpStr->rfind(end);
if (pos == std::string::npos) return false;
if (pos + end.size() == tmpStr->size()) return true;
return false;
}
cpps_value cpps_string_ltrim(cpps_value s)
{
std::string* tmpStr = cpps_get_string(s);
if (tmpStr->empty())
{
return s;
}
std::string::iterator p = find_if(tmpStr->begin(), tmpStr->end(), [](char code) { return !isspace(code); });
tmpStr->erase(tmpStr->begin(), p);
return s;
}
std::string cpps_string_real_join(std::string sep, std::vector<std::string> & vec) {
std::string ret;
for (auto s : vec) {
ret += s;
ret += sep;
}
return ret;
}
std::string cpps_string_join(std::string sep, cpps_vector* vec) {
std::string ret;
for (auto s : vec->realvector()) {
ret += cpps_to_string(s);
ret += sep;
}
return ret;
}
std::string cpps_string_between(std::string front, std::string before, cpps_vector* vec) {
std::string ret;
for (auto s : vec->realvector()) {
ret += front;
ret += cpps_to_string(s);
ret += before;
}
return ret;
}
cpps_value cpps_string_rtrim(cpps_value s)
{
if (s.tt != CPPS_TSTRING) return nil;
cpps_cppsclassvar* cppsclassvar = (cpps_cppsclassvar*)s.value.domain;
std::string *tmpStr = (std::string *)cppsclassvar->getclsptr();
if (tmpStr->empty())
{
return s;
}
std::string::reverse_iterator p = find_if(tmpStr->rbegin(), tmpStr->rend(), [](char code) { return !isspace(code); });
tmpStr->erase(p.base(), tmpStr->end());
return s;
}
cpps_value cpps_string_trim(cpps_value s)
{
if (s.tt != CPPS_TSTRING) return false;
std::string* tmpStr = cpps_get_string(s);
if (tmpStr->empty())
{
return s;
}
cpps_string_ltrim(cpps_string_rtrim(s));
return s;
}
cpps_value cpps_string_chr(C*c,cpps_integer ch)
{
std::string ret;
ret.push_back(static_cast<char>(ch));
return cpps_value(c,ret);
}
cpps_value cpps_string_push_back(cpps_value src, cpps_integer c)
{
if (src.tt != CPPS_TSTRING) return nil;
std::string* tmpStr = cpps_get_string(src);
tmpStr->push_back(static_cast<char>(c));
return src;
}
cpps_integer cpps_string_unicode_charCodeAt(cpps_value src, cpps_integer pos)
{
if (src.tt != CPPS_TSTRING) return 0;
std::string* tmpStr = cpps_get_string(src);
if (tmpStr->size() % 2 != 0) return 0;
if (tmpStr->size() / 2 <= size_t(pos)) return 0;
unsigned short ret = *((unsigned short*)(tmpStr->c_str() + pos * 2));
return static_cast<cpps_integer>(ret);
}
cpps_value cpps_string_unicode_fromCodeAt(C*c,cpps_vector* vec)
{
std::string ret = "";
for (size_t i = 0; i < size_t(vec->size()); i++)
{
unsigned short code = static_cast<unsigned short>(vec->at(i).value.integer);
ret.append((char *)&code,2);
}
return cpps_value(c,ret);
}
cpps_integer cpps_string_isalnum(cpps_integer i) {
return (cpps_integer)isalnum((int32)i);
}
cpps_integer cpps_string_isalpha(cpps_integer i) {
return (cpps_integer)isalpha((int32)i);
}
cpps_integer cpps_string_isspace(cpps_integer i) {
return (cpps_integer)isspace((int32)i);
}
void cpps_regstring(C *c)
{
cpps::_module(c)[
_class<cpps::string>("String")
.def("size", &cpps::string::cpps_size)
.def("length", &cpps::string::cpps_size)
.def("find", &cpps::string::cpps_string_find)
.def("rfind", &cpps::string::cpps_string_rfind)
.def("replace", &cpps::string::cpps_string_replace)
.def("clear", &cpps::string::cpps_string_clear)
.def("copyto", &cpps::string::cpps_string_copyto)
.def_inside("split", &cpps::string::cpps_string_split)
.def_inside("cut", &cpps::string::cpps_string_cut)
.def("strcut", &cpps::string::cpps_string_strcut)
.def_inside("strcuts", &cpps::string::cpps_string_strcuts)
.def("empty", &cpps::string::cpps_string_empty)
.def("substr", &cpps::string::cpps_string_sub)
.def("at", &cpps::string::cpps_string_at)
.def("erase", &cpps::string::cpps_string_erase)
.def("tolower", &cpps::string::cpps_string_tolower)
.def("toupper", &cpps::string::cpps_string_toupper)
.def("trim", &cpps::string::cpps_string_trim)
.def("ltrim", &cpps::string::cpps_string_ltrim)
.def("rtrim", &cpps::string::cpps_string_rtrim)
.def("join", &cpps::string::cpps_string_join)
.def("startswith", &cpps::string::cpps_string_startswith)
.def("endswith", &cpps::string::cpps_string_endswith)
.def("pop_back", &cpps::string::cpps_string_pop_back)
.def("push_back", &cpps::string::cpps_string_push_back)
.def("append", &cpps::string::cpps_string_append)
.def("title", &cpps::string::cpps_string_title)
.def("center", &cpps::string::cpps_string_center)
.def("isalnum", &cpps::string::cpps_string_isalnum)
.def("isalpha", &cpps::string::cpps_string_isalpha)
.def("isdecimal", &cpps::string::cpps_string_isdecimal)
.def("resize", &cpps::string::cpps_string_resize)
.def("insert", &cpps::string::cpps_string_insert)
];
cpps::_module(c,"string")[
def("find", cpps_string_find),
def("rfind", cpps_string_rfind),
def("length", cpps_string_len),
def("strlen", cpps_string_strlen),
def("replace", cpps_string_replace),
def("clear", cpps_string_clear),
def("copyto", cpps_string_copyto),
def_inside("split", cpps_string_split),
def_inside("cut", cpps_string_cut),
def("strcut", cpps_string_strcut),
def_inside("strcuts", cpps_string_strcuts),
def("empty", cpps_string_empty),
def("substr",cpps_string_sub),
defvar(c, "npos",(cpps_integer)std::string::npos),
def("at", cpps_string_at),
def("format", cpps_string_format),
def("lower", cpps_string_lower),
def("upper", cpps_string_upper),
def("trim", cpps_string_trim),
def("ltrim", cpps_string_ltrim),
def("rtrim", cpps_string_rtrim),
def("join", cpps_string_join),
def("between", cpps_string_between),
def("startswith", cpps_string_startswith),
def("endswith", cpps_string_endswith),
def("pop_back", cpps_string_pop_back),
def_inside("chr",cpps_string_chr),
def("push_back", cpps_string_push_back),
def("unicode_charCodeAt",cpps_string_unicode_charCodeAt),
def_inside("unicode_fromCodeAt",cpps_string_unicode_fromCodeAt),
def("isalnum",cpps_string_isalnum),
def("isalpha", cpps_string_isalpha),
def("isspace",cpps_string_isspace)
];
}
cpps_integer string::cpps_size()
{
return (cpps_integer)__str.size();
}
cpps_integer string::cpps_string_find(std::string v2, object off)
{
size_t pos = 0;
if (off.isint()) pos = (size_t)off.toint();
return (cpps_integer)__str.find(v2, pos);
}
cpps_integer string::cpps_string_rfind(std::string v2, object off)
{
size_t pos = 0;
if (off.isint()) pos = (size_t)off.toint();
return (cpps_integer)__str.rfind(v2, pos);
}
cpps::string* string::cpps_string_replace(std::string v2, std::string v3)
{
std::string::size_type pos = 0;
while ((pos = __str.find(v2, pos)) != std::string::npos)
{
__str.replace(pos, v2.length(), v3);
pos += v3.length();
}
return this;
}
void string::cpps_string_clear()
{
__str.clear();
}
void string::cpps_string_copyto(cpps::string* tar, object off, object len)
{
size_t noff = 0;
size_t nlen = std::string::npos;
if (off.isint()) noff = (size_t)off.toint();
if (len.isint()) nlen = (size_t)len.toint();
tar->__str.append(__str.substr(noff, nlen));
}
cpps::cpps_value string::cpps_string_split(C*c,std::string v2, object len)
{
cpps_integer nlen = -1;
if (len.isint()) nlen = len.toint();
cpps_vector* vec;
cpps_value ret;
newclass<cpps_vector>(c, &vec,&ret);
if (__str.empty()) return ret;
const char* a = __str.c_str(); const char* b;
while (true)
{
b = strstr(a, v2.c_str());
if (!b) b = a + strlen(a);
std::string s;
s.append(a, strlen(a) - strlen(b));
vec->push_back(cpps_value(c, s));
if (nlen != -1 && vec->size() >= nlen) break;
//如果到了结尾那就出去吧。
if (strlen(b) == 0 || strlen(b) == 1) break;
else a = b + v2.size();
}
return ret;
}
cpps::cpps_value string::cpps_string_cut(C* c, cpps_integer len)
{
cpps_vector* vec;
cpps_value ret;
newclass<cpps_vector>(c, &vec, &ret);
size_t ncount = (size_t)len;
size_t FileSize = __str.size();
size_t pos1 = 0;
for (size_t j = 0; j < FileSize / ncount + 1; j++)
{
size_t res = FileSize - pos1 < ncount ? FileSize - pos1 : ncount;
if (res != 0)
{
std::string* s;
cpps_value sv;
newclass<std::string>(c, &s,&sv);
s->append(__str.c_str() + pos1, res);
vec->push_back(sv);
pos1 += res;
}
}
return ret;
}
std::string string::cpps_string_strcut(std::string v2, std::string v3)
{
const char* strtmp1 = strstr(__str.c_str(), v2.c_str());
if (!strtmp1) return "";
const char* strtmp2 = strstr(strtmp1 + v2.size(), v3.c_str());
if (!strtmp2) return "";
std::string out;
out.append(strtmp1 + v2.size(), strtmp2 - strtmp1 - v2.size());
return out;
}
cpps::cpps_value string::cpps_string_strcuts(C* c, std::string start, std::string end)
{
cpps_vector* vec;
cpps_value ret;
newclass<cpps_vector>(c, &vec,&ret);
const char* begin = __str.c_str();
while (true)
{
const char* strtmp1 = strstr(begin, start.c_str());
if (!strtmp1) return ret;
const char* strtmp2 = strstr(strtmp1 + start.size(), end.c_str());
if (!strtmp2) return ret;
std::string out;
out.append(strtmp1 + start.size(), strtmp2 - strtmp1 - start.size());
vec->push_back(cpps_value(c, out));
begin = strtmp2 + end.size();
}
return ret;
}
bool string::cpps_string_empty()
{
return __str.empty();
}
bool string::cpps_string_startswith(std::string v)
{
return __str.find(v) == 0;
}
bool string::cpps_string_endswith(std::string v)
{
size_t pos = __str.rfind(v);
if (pos == std::string::npos) return false;
if (pos + v.size() == __str.size()) return true;
return false;
}
std::string string::cpps_string_sub(cpps_integer off, object len)
{
size_t nlen = std::string::npos;
if (len.isint()) nlen = (size_t)len.toint();
return __str.substr(size_t(off), nlen);
}
cpps_integer string::cpps_string_at(cpps_integer off)
{
return (cpps_integer)__str.at(size_t(off));
}
cpps::string* string::cpps_string_erase(cpps_integer off,object _count)
{
if(_count.isint())
__str.erase((size_t)off, (size_t) _count.toint());
else
__str.erase((size_t)off);
return this;
}
std::string string::cpps_string_tolower()
{
std::string ret;
ret.resize(__str.size());
for (size_t i = 0; i < __str.size(); i++) {
ret[i] = (char)tolower(__str.at(i));
}
return ret;
}
std::string string::cpps_string_toupper()
{
std::string ret;
ret.resize(__str.size());
for (size_t i = 0; i < __str.size(); i++) {
ret[i] = (char)toupper(__str.at(i));
}
return ret;
}
std::string string::cpps_string_join(cpps_vector* vec)
{
std::string ret;
for (auto s : vec->realvector()) {
ret += cpps_to_string(s);
ret += __str.c_str();
}
return ret;
}
void string::cpps_string_trim()
{
cpps_string_rtrim();
cpps_string_ltrim();
}
void string::cpps_string_ltrim()
{
std::string::iterator p = find_if(__str.begin(), __str.end(), [](char code) { return !isspace(code); });
__str.erase(__str.begin(), p);
}
void string::cpps_string_rtrim()
{
std::string::reverse_iterator p = find_if(__str.rbegin(), __str.rend(), [](char code) { return !isspace(code); });
__str.erase(p.base(), __str.end());
}
void string::cpps_string_pop_back(object len)
{
size_t nlen = 1;
if (len.isint()) nlen = (size_t)len.toint();
for (size_t i = 0; i < nlen; i++)
{
__str.pop_back();
}
}
void string::cpps_string_push_back(cpps_integer charcode)
{
__str.push_back((const char)charcode);
}
void string::cpps_string_append(std::string v)
{
__str.append(v);
}
std::string string::cpps_string_title()
{
std::string ret;
ret.resize(__str.size());
for (size_t i = 0; i < __str.size(); ) {
if (i == 0 && __str[i] >= 'a' && __str[i] <= 'z') {
ret[i] = __str[i] - 32;
++i;
}
else if((__str[i] == '\t' || __str[i] == ' ' ) && __str[i+1] >= 'a' && __str[i+1] <= 'z') {
ret[i] = __str[i];
ret[i+1] = __str[i+1] - 32;
i+=2;
}
else {
ret[i] = __str[i];
++i;
}
}
return ret;
}
std::string string::cpps_string_center(cpps_integer width)
{
if (width <= (cpps_integer)__str.size()) return __str;
std::string ret;
ret.resize(width);
cpps_integer srcwidth = (cpps_integer)__str.size();
cpps_integer leftwidth = (cpps_integer)((width - srcwidth) / 2);
cpps_integer rightwidth = width - leftwidth - srcwidth;
cpps_integer i = 0;
for (;i < leftwidth; ++i){
ret[i] = ' ';
}
for (i = 0; i < srcwidth; ++i) {
ret[i] = __str[i];
}
for (i = 0; i < rightwidth; ++i) {
ret[i] = ' ';
}
return ret;
}
bool string::cpps_string_isalnum()
{
for (size_t i = 0; i < __str.size(); ++i) {
if (!isalnum(__str[i])) return false;
}
return true;
}
bool string::cpps_string_isalpha()
{
for (size_t i = 0; i < __str.size(); ++i) {
if (!isalpha(__str[i])) return false;
}
return true;
}
bool string::cpps_string_isspace()
{
for (size_t i = 0; i < __str.size(); ++i) {
if (!isspace(__str[i])) return false;
}
return true;
}
bool string::cpps_string_isdecimal() {
for (size_t i = 0; i < __str.size(); i++) {
if (__str.at(i) == '-' && __str.size() > 1) // 有可能出现负数
continue;
if (__str.at(i) > '9' || __str.at(i) < '0')
return false;
}
return true;
}
void string::cpps_string_resize(cpps_integer s) {
__str.resize((size_t)s);
}
void string::cpps_string_insert_real(size_t &off, object& v)
{
size_t len = 1;
if (v.isint())
__str.insert((size_t)off, 1, (char)v.toint());
else if (v.isstring()) {
std::string str = v.tostring();
__str.insert(off, str);
len = str.size();
}
else if(v.ischar())
__str.insert((size_t)off, 1, v.tochar());
else if (v.isvector())
{
len = 0;
for (auto& v2 : object::vector(v)) {
object o = object(v2);
cpps_string_insert_real(off, o);
}
}
off += len;
}
void string::cpps_string_insert(cpps_integer off, object v) {
size_t pos = (size_t)off;
cpps_string_insert_real(pos, v);
}
std::string& string::real()
{
return __str;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

CPPS是一种轻量级的嵌入式脚本语言,其语法类似于C++。它具有当前主流语言的许多特性,包括协程、面向对象、lambda、闭包、泛型变量、自定义模块支持、GC垃圾收集和跨平台。CPPS将程序解释为字节码,通过内置语法解析在虚拟机中运行
取消

发行版 (3)

全部

开源评估指数源自 OSS-Compass 评估体系,评估体系围绕以下三个维度对项目展开评估:

1. 开源生态

  • 生产力:来评估开源项目输出软件制品和开源价值的能力。
  • 创新力:用于评估开源软件及其生态系统的多样化程度。
  • 稳健性:用于评估开源项目面对多变的发展环境,抵御内外干扰并自我恢复的能力。

2. 协作、人、软件

  • 协作:代表了开源开发行为中协作的程度和深度。
  • 人:观察开源项目核心人员在开源项目中的影响力,并通过第三方视角考察用户和开发者对开源项目的评价。
  • 软件:从开源项目对外输出的制品评估其价值最终落脚点。也是开源评估最"古老"的主流方向之一"开源软件" 的具体表现。

3. 评估模型

    基于"开源生态"与"协作、人、软件"的维度,找到与该目标直接或间接相关的可量化指标,对开源项目健康与生态进行量化评估,最终形成开源评估指数。

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppscript/cpps.git
git@gitee.com:cppscript/cpps.git
cppscript
cpps
cpps
v1.0.2
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /