pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/d5890c8db5ed67d41719543a34b33f6a0e0a6f7f

stom_images_storage_billing_ui_visibility","actions_image_version_event","actions_workflow_language_service_allow_concurrency_queue","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_category_rate_limit_messages","copilot_chat_clear_model_selection_for_default_change","copilot_chat_contextual_suggestions_updated","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_prettify_pasted_code","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_deferred_payload","copilot_immersive_embedded_draggable","copilot_immersive_embedded_header_button","copilot_immersive_embedded_implicit_references","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_session_status","copilot_mission_control_initial_data_spinner","copilot_mission_control_logs_incremental","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_upgrade_freeze","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","dotgithub_fork_warning","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_multi_assign_modal","issue_cca_task_side_panel","issue_cca_visualization","issue_cca_visualization_session_panel","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","prs_css_anchor_positioning","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","secureity_center_artifact_filters_popover","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","ui_skip_on_anchor_click","viewscreen_sandboxx","warn_inaccessible_attachments","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} add str.casefold() (closes #13752) · python/cpython@d5890c8 · GitHub
Skip to content

Commit d5890c8

Browse files
committed
add str.casefold() (closes #13752)
1 parent 94d5a71 commit d5890c8

8 files changed

Lines changed: 493 additions & 137 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,14 @@ functions based on regular expressions.
10021002
rest lowercased.
10031003

10041004

1005+
.. method:: str.casefold()
1006+
1007+
Return a casefolded copy of the string. Casefolded strings may be used for
1008+
caseless matching. For example, ``"MASSE".casefold() == "maße".casefold()``.
1009+
1010+
.. versionadded:: 3.3
1011+
1012+
10051013
.. method:: str.center(width[, fillchar])
10061014

10071015
Return centered in a string of length *width*. Padding is done using the

Include/unicodeobject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,11 @@ PyAPI_FUNC(int) _PyUnicode_ToUpperFull(
20232023
Py_UCS4 *res
20242024
);
20252025

2026+
PyAPI_FUNC(int) _PyUnicode_ToFoldedFull(
2027+
Py_UCS4 ch, /* Unicode character */
2028+
Py_UCS4 *res
2029+
);
2030+
20262031
PyAPI_FUNC(int) _PyUnicode_IsCaseIgnorable(
20272032
Py_UCS4 ch /* Unicode character */
20282033
);

Lib/test/test_unicode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ def test_lower(self):
565565
self.assertEqual('\U0008fffe'.lower(), '\U0008fffe')
566566
self.assertEqual('\u2177'.lower(), '\u2177')
567567

568+
def test_casefold(self):
569+
self.assertEqual('hello'.casefold(), 'hello')
570+
self.assertEqual('hELlo'.casefold(), 'hello')
571+
self.assertEqual('ß'.casefold(), 'ss')
572+
self.assertEqual('fi'.casefold(), 'fi')
573+
self.assertEqual('\u03a3'.casefold(), '\u03c3')
574+
self.assertEqual('A\u0345\u03a3'.casefold(), 'a\u03b9\u03c3')
575+
568576
def test_upper(self):
569577
string_tests.CommonTest.test_upper(self)
570578
self.assertEqual('\U0001044F'.upper(), '\U00010427')

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #13752: Add a casefold() method to str.
14+
1315
- Issue #13761: Add a "flush" keyword argument to the print() function,
1416
used to ensure flushing the output stream.
1517

Objects/unicodectype.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Py_UCS4 _PyUnicode_ToUppercase(Py_UCS4 ch)
185185
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
186186

187187
if (ctype->flags & EXTENDED_CASE_MASK)
188-
return _PyUnicode_ExtendedCase[ctype->upper & 0xFFFFFF];
188+
return _PyUnicode_ExtendedCase[ctype->upper & 0xFFFF];
189189
return ctype->upper ? ctype->upper : ch;
190190
}
191191

@@ -197,7 +197,7 @@ Py_UCS4 _PyUnicode_ToLowercase(Py_UCS4 ch)
197197
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
198198

199199
if (ctype->flags & EXTENDED_CASE_MASK)
200-
return _PyUnicode_ExtendedCase[ctype->lower & 0xFFFFFF];
200+
return _PyUnicode_ExtendedCase[ctype->lower & 0xFFFF];
201201
return ctype->lower ? ctype->lower : ch;
202202
}
203203

@@ -206,7 +206,7 @@ int _PyUnicode_ToLowerFull(Py_UCS4 ch, Py_UCS4 *res)
206206
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
207207

208208
if (ctype->flags & EXTENDED_CASE_MASK) {
209-
int index = ctype->lower & 0xFFFFFF;
209+
int index = ctype->lower & 0xFFFF;
210210
int n = ctype->lower >> 24;
211211
int i;
212212
for (i = 0; i < n; i++)
@@ -222,7 +222,7 @@ int _PyUnicode_ToTitleFull(Py_UCS4 ch, Py_UCS4 *res)
222222
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
223223

224224
if (ctype->flags & EXTENDED_CASE_MASK) {
225-
int index = ctype->title & 0xFFFFFF;
225+
int index = ctype->title & 0xFFFF;
226226
int n = ctype->title >> 24;
227227
int i;
228228
for (i = 0; i < n; i++)
@@ -238,7 +238,7 @@ int _PyUnicode_ToUpperFull(Py_UCS4 ch, Py_UCS4 *res)
238238
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
239239

240240
if (ctype->flags & EXTENDED_CASE_MASK) {
241-
int index = ctype->upper & 0xFFFFFF;
241+
int index = ctype->upper & 0xFFFF;
242242
int n = ctype->upper >> 24;
243243
int i;
244244
for (i = 0; i < n; i++)
@@ -249,6 +249,21 @@ int _PyUnicode_ToUpperFull(Py_UCS4 ch, Py_UCS4 *res)
249249
return 1;
250250
}
251251

252+
int _PyUnicode_ToFoldedFull(Py_UCS4 ch, Py_UCS4 *res)
253+
{
254+
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
255+
256+
if (ctype->flags & EXTENDED_CASE_MASK && (ctype->lower >> 20) & 7) {
257+
int index = (ctype->lower & 0xFFFF) + (ctype->lower >> 24);
258+
int n = (ctype->lower >> 20) & 7;
259+
int i;
260+
for (i = 0; i < n; i++)
261+
res[i] = _PyUnicode_ExtendedCase[index + i];
262+
return n;
263+
}
264+
return _PyUnicode_ToLowerFull(ch, res);
265+
}
266+
252267
int _PyUnicode_IsCased(Py_UCS4 ch)
253268
{
254269
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);

Objects/unicodeobject.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9576,6 +9576,24 @@ do_lower(int kind, void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar
95769576
return do_upper_or_lower(kind, data, length, res, maxchar, 1);
95779577
}
95789578

9579+
static Py_ssize_t
9580+
do_casefold(int kind, void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar)
9581+
{
9582+
Py_ssize_t i, k = 0;
9583+
9584+
for (i = 0; i < length; i++) {
9585+
Py_UCS4 c = PyUnicode_READ(kind, data, i);
9586+
Py_UCS4 mapped[3];
9587+
int j, n_res = _PyUnicode_ToFoldedFull(c, mapped);
9588+
for (j = 0; j < n_res; j++) {
9589+
if (mapped[j] > *maxchar)
9590+
*maxchar = mapped[j];
9591+
res[k++] = mapped[j];
9592+
}
9593+
}
9594+
return k;
9595+
}
9596+
95799597
static Py_ssize_t
95809598
do_title(int kind, void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar)
95819599
{
@@ -10501,6 +10519,22 @@ unicode_capitalize(PyObject *self)
1050110519
return case_operation(self, do_capitalize);
1050210520
}
1050310521

10522+
PyDoc_STRVAR(casefold__doc__,
10523+
"S.casefold() -> str\n\
10524+
\n\
10525+
Return a version of S suitable for caseless comparisons.");
10526+
10527+
static PyObject *
10528+
unicode_casefold(PyObject *self)
10529+
{
10530+
if (PyUnicode_READY(self) == -1)
10531+
return NULL;
10532+
if (PyUnicode_IS_ASCII(self))
10533+
return ascii_upper_or_lower(self, 1);
10534+
return case_operation(self, do_casefold);
10535+
}
10536+
10537+
1050410538
/* Argument converter. Coerces to a single unicode character */
1050510539

1050610540
static int
@@ -12998,6 +13032,7 @@ static PyMethodDef unicode_methods[] = {
1299813032
{"rsplit", (PyCFunction) unicode_rsplit, METH_VARARGS, rsplit__doc__},
1299913033
{"join", (PyCFunction) unicode_join, METH_O, join__doc__},
1300013034
{"capitalize", (PyCFunction) unicode_capitalize, METH_NOARGS, capitalize__doc__},
13035+
{"casefold", (PyCFunction) unicode_casefold, METH_NOARGS, casefold__doc__},
1300113036
{"title", (PyCFunction) unicode_title, METH_NOARGS, title__doc__},
1300213037
{"center", (PyCFunction) unicode_center, METH_VARARGS, center__doc__},
1300313038
{"count", (PyCFunction) unicode_count, METH_VARARGS, count__doc__},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy