Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121206 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41844 invoked from network); 2 Oct 2023 14:24:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Oct 2023 14:24:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 838EC180507 for ; Mon, 2 Oct 2023 07:24:56 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 2 Oct 2023 07:24:56 -0700 (PDT) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-57b67c84999so9477434eaf.3 for ; Mon, 02 Oct 2023 07:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696256695; x=1696861495; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pRO4b5kBb19akTaeKF0A13Qa47aTFSk9+spMorj2a0U=; b=B3GS9ewB8Sspu1lvhzxWHt6IMolp3uZZEJgrwE1ZK++6tJo06WaJwElmrn269MNuWZ tNhhY3+ToEAgM0BtTmDTfTcpN4q1ODlM2ZSuTW8NkhjRf74a+NL2SPPlBc2L8XxqM25I bS3I9plKi+AISQW1vM0lRM1rIVXfV7WC7BNxUODMRumdUuBSo6rvqC+rZGBkunRGU/SP xO+3jFVM0MpdrOLG+0iCpMRewL6SxPBe0Pv8N96BeSqFhSAE6E67I8UTx6cUb/6w6F7i YIJWSEOUzZ8FAbCYMu0b9HkAgVCYsaB4g9zLHLKQkUv/o1zAvJXmwLKwOIWqxRjHnSEd BNdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696256695; x=1696861495; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pRO4b5kBb19akTaeKF0A13Qa47aTFSk9+spMorj2a0U=; b=HVH+N7BbcIKzcA58y82XrBprx6QzgiVsZq6t0K4W5T2VNmy232kmS1T9OvEqlP22gK J0SRzr9kkbp8y49bzgPO4O6Yg7G5E068tmNnaksu0srMTieXRDIeXm92rkvieLOnfsfE GZMSUYad1/a0FfYl1p2lSYFhSd47NxpNK1iQjCMYcnhLu7FJ1VAH9hwX7/qlMRoQb12U ZzpAi7hnPPSkn0VWAvM9lPcPf3Uzkc9/H6jX47c+6cZkSwzh7Hmy5xpAKvHKbwO82Ag5 Bx/GxX+W4XTN2l+tcNtYCbaTyNYwPScfFeEUMHmUu+8eK3SMSSi8fpeZ1ToiJILqcTDF DvWA== X-Gm-Message-State: AOJu0Yz7Npjn25LvJBRpAqbAzronPXQ9ue2Dri/lNrWnQgkJTJITWEpZ Y7xmEcgxxzWbJ699AoAVhIGQIcyFJy1Tl5f8ClM= X-Google-Smtp-Source: AGHT+IHDkc6KxUp2lBA9ZFuOalFyAa13a8ZV5JFvCta+7EAZBX76Fc6/rqPysTQEyO1JIxXFRM0cW1OrvHW8tqF25Xk= X-Received: by 2002:a4a:9c85:0:b0:57b:3b48:6f11 with SMTP id z5-20020a4a9c85000000b0057b3b486f11mr11211090ooj.4.1696256695076; Mon, 02 Oct 2023 07:24:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 2 Oct 2023 16:24:18 +0200 Message-ID: To: youkidearitai Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] trim support for multibyte spaces From: divinity76@gmail.com (Hans Henrik Bergan) add a void str_dump(const size_t strlen, const char *str) { printf("string(%zu) \"", strlen); fwrite(str, strlen, 1, stdout); printf("\"\n"); } then replace the string_view stuff with size_t teststrlen =3D strlen(teststr); str_dump(teststrlen, teststr); mb_trim(&teststrlen, &teststr, trim_lengths_num, trim_lengths, trim_cha= rs); str_dump(teststrlen, teststr); and it should be pure C, i think On Mon, 2 Oct 2023 at 15:36, youkidearitai wrote: > > Hi, Hans. > > Thank you very much for your code. And sorry for late. > I confirmed works fine. > https://gist.github.com/youkidearitai/0018dee27353c00aebaff3bf57c5b8c6 > > However, this code is C++17, php-src is C code. > If you would like contribute, I would like written to C code. > > Regards > Yuya > > 2023=E5=B9=B410=E6=9C=881=E6=97=A5(=E6=97=A5) 19:46 Hans Henrik Bergan : > > > > .. probably a bunch of stuff that *could* be optimized or done better, > > but one i saw just now is that instead of 2x nested loops and goto, > > the outer loop and labels could be removed and the `goto > > remove_from_start_continue_2;` could be replaced with `i=3D-1;` eg > > > > size_t local_strlen =3D *strlen; > > char *local_str =3D *str; > > for (size_t i =3D 0; i < trim_lengths_num; ++i) > > { > > if (local_strlen >=3D trim_lengths[i] && memcmp(local_str, > > trim_chars[i], trim_lengths[i]) =3D=3D 0) > > { > > local_strlen -=3D trim_lengths[i]; > > local_str +=3D trim_lengths[i]; > > i =3D -1; > > } > > } > > > > 2x nested loops reduced to 1 loop, and goto removed~ > > > > On Sun, 1 Oct 2023 at 10:43, Hans Henrik Bergan = wrote: > > > > > > > If have any idea, feel free to comment to me. > > > > > > i think the C code would look something like > > > > > > > > > void mb_trim(size_t *strlen, char **str, const size_t > > > trim_lengths_num, const size_t *trim_lengths, const char **trim_chars= ) > > > { > > > size_t local_strlen =3D *strlen; > > > char *local_str =3D *str; > > > for (;;) > > > { > > > for (size_t i =3D 0; i < trim_lengths_num; ++i) > > > { > > > if (local_strlen >=3D trim_lengths[i] && memcmp(local_str= , > > > trim_chars[i], trim_lengths[i]) =3D=3D 0) > > > { > > > local_strlen -=3D trim_lengths[i]; > > > local_str +=3D trim_lengths[i]; > > > goto remove_from_start_continue_2; > > > } > > > } > > > break; > > > remove_from_start_continue_2:; > > > } > > > for (;;) > > > { > > > for (size_t i =3D 0; i < trim_lengths_num; ++i) > > > { > > > if (local_strlen >=3D trim_lengths[i] && memcmp(((local_s= tr > > > + local_strlen) - trim_lengths[i]), trim_chars[i], trim_lengths[i]) = =3D=3D > > > 0) > > > { > > > local_strlen -=3D trim_lengths[i]; > > > goto remove_from_end_continue_2; > > > } > > > } > > > break; > > > remove_from_end_continue_2:; > > > } > > > memmove(*str, local_str, local_strlen); > > > char *newstr =3D (char *)realloc(*str, local_strlen); > > > if (newstr !=3D nullptr) > > > { > > > *strlen =3D local_strlen; > > > *str =3D newstr; > > > } > > > else > > > { > > > // some error handling > > > } > > > } > > > > > > with my simple testcode looking like > > > > > > int main() > > > { > > > const char *trim_chars[] =3D { > > > " ", > > > "!", > > > // utf8 whitespace: > > > "\xE2\x80\x80", // EN QUAD > > > "\xE2\x80\x81", // EM QUAD > > > "\xE2\x80\x82", // EN SPACE > > > "\xE2\x80\x83", // EM SPACE > > > "\xE2\x80\x84", // THREE-PER-EM SPACE > > > "\xE2\x80\x85", // FOUR-PER-EM SPACE > > > "\xE2\x80\x86", // SIX-PER-EM SPACE > > > }; > > > size_t trim_lengths[] =3D { > > > strlen(trim_chars[0]), > > > strlen(trim_chars[1]), > > > strlen(trim_chars[2]), > > > strlen(trim_chars[3]), > > > strlen(trim_chars[4]), > > > strlen(trim_chars[5]), > > > strlen(trim_chars[6]), > > > strlen(trim_chars[7]), > > > strlen(trim_chars[8]), > > > }; > > > size_t trim_lengths_num =3D sizeof(trim_lengths) / sizeof(trim_le= ngths[0]); > > > char *teststr =3D strdup(" ! \xE2\x80\x80\xE2\x80\x81\xE2\x80\x= 82 > > > Hello World ! \xE2\x80\x83\xE2\x80\x84\xE2\x80\x85\xE2\x80\x86 ! > > > "); > > > // char *teststr =3D strdup(" ! Hello World ! ! "= ); > > > size_t teststrlen =3D strlen(teststr); > > > std::cout << teststrlen << ": \"" << std::string_view(teststr, > > > teststrlen) << "\"" << std::endl; > > > mb_trim(&teststrlen, &teststr, trim_lengths_num, trim_lengths, tr= im_chars); > > > std::cout << teststrlen << ": \"" << std::string_view(teststr, > > > teststrlen) << "\"" << std::endl; > > > return 0; > > > } > > > > > > > > > On Sat, 30 Sept 2023 at 13:16, youkidearitai wrote: > > > > > > > > 2023=E5=B9=B49=E6=9C=8830=E6=97=A5(=E5=9C=9F) 17:42 Saki Takamachi = : > > > > > > > > > > > I also want to trim function of multibyte trim functions. > > > > > > > > > > > I think that in addition to mb_trim, > > > > > mb_ltrim and mb_rtrim are also necessary. > > > > > > > > > > Hi. > > > > > > > > > > Having a new option besides regex sounds like a good idea for me,= as a user of a language that benefits from `mb_trim()`. > > > > > > > > > > Perhaps users are more intuitive about the usefulness of those fu= nctions who have spent more time cleaning "multibyte spaces". > > > > > > > > Hi > > > > > > > > Thanks for reply. > > > > I'm trying implements to trim for multibyte function. > > > > Please give me some time. > > > > > > > > If have any idea, feel free to comment to me. > > > > > > > > Regards > > > > Yuya > > > > > > > > -- > > > > --------------------------- > > > > Yuya Hamada (tekimen) > > > > - https://tekitoh-memdhoi.info > > > > - https://github.com/youkidearitai > > > > ----------------------------- > > > > > > > > -- > > > > PHP Internals - PHP Runtime Development Mailing List > > > > To unsubscribe, visit: https://www.php.net/unsub.php > > > > > > > > -- > --------------------------- > Yuya Hamada (tekimen) > - https://tekitoh-memdhoi.info > - https://github.com/youkidearitai > ----------------------------- > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >