Code Monger, cyclist, sim racer and driving enthusiast.
8575 stories
·
6 followers

just asking questions

2 Shares

an image of a person shrugging and the text "If we can control the weather why would you be on the side that can't".

source: vvvvvv.facebook.corn
Read the whole story
LeMadChef
6 hours ago
reply
Denver, CO
jhamill
7 hours ago
reply
California
Share this story
Delete

Hackers targeted Android users by exploiting zero-day bug in Qualcomm chips | TechCrunch

1 Comment and 2 Shares

On Monday, chipmaker Qualcomm confirmed that hackers exploited a zero-day — meaning a security flaw that was unknown to the hardware maker when it was abused — in dozens of its chipsets found in popular Android devices.

The zero-day vulnerability, officially designated CVE-2024-43047, “may be under limited, targeted exploitation,” according to Qualcomm, citing unspecified “indications” from Google’s Threat Analysis Group, the company’s research unit that investigates government hacking threats. Amnesty International’s Security Lab, which works to protect civil society from digital surveillance and spyware threats, confirmed Google’s assessment, Qualcomm said.

U.S. cybersecurity agency CISA included the Qualcomm flaw in its list of vulnerabilities that are known to be, or have been, exploited. 

At this point, there aren’t many details about who was exploiting this vulnerability “in the wild” — meaning that whoever was using the zero-day was targeting individuals in real hacking campaigns. It also is not yet known which individuals were targeted, or why. 

Qualcomm’s spokesperson Catherine Baker told TechCrunch that the company commends “the researchers from Google Project Zero and Amnesty International Security Lab for using coordinated disclosure practices,” allowing the company to roll out fixes for the vulnerability. 

The chipmaker referred to Amnesty and Google for more details about the threat activity. 

Amnesty spokesperson Hajira Maryam told TechCrunch that the nonprofit will have research about this vulnerability “due to be out soon.”

Google spokesperson Kimberly Samra said TAG has nothing to add at the moment.

Qualcomm’s spokesperson said that “fixes have been made available to our customers as of September 2024.” It’s now up to Qualcomm’s customers — the Android device makers that use the vulnerable chipsets — to release the patch to their customers’ devices. 

In its advisory, Qualcomm listed 64 different chipsets affected by this vulnerability, including the company’s flagship Snapdragon 8 (Gen 1) mobile platform, which is used in dozens of Android phones, including some made by Motorola, Samsung, OnePlus, Oppo, Xiaomi, and ZTE — meaning millions of users around the world are potentially vulnerable. 

That being said, the fact that Google and Amnesty are investigating the use of this zero-day under “limited, targeted exploitation” suggests the hacking campaign was likely used against specific individuals, rather than a large number of targets. 

Brian Heater contributed reporting.

UPDATE, October 9, 1:07 p.m. ET: This story was updated to include Amnesty’s comment.

Read the whole story
LeMadChef
12 hours ago
reply
BuT aNdRoId Is MoRe SeCuRe!
Denver, CO
acdha
13 hours ago
reply
Washington, DC
Share this story
Delete

The Snackle Box Has Revolutionized The Road Trip Snack Experience

1 Share

I highly recommend ignoring basically any trendy item you see on Instagram or TikTok. I find that high hopes usually give way to an inevitable letdown when you open that package from Temu and realize some $12 piece of questionably food-grade plastic isn’t going to save your relationship with your estranged uncle. Unless that package contains the Snackle Box.

It is with surprisingly little regret that I inform you that the ‘Snackle Box’ is good. Maybe great. All those Instagram moms and TikTok matriarchs might be wrong about raw milk and sinister underground pizza joints, but the idea that an easily cleanable and collapsable portable snack device will change your life is real.

Yes, I am talking about a rectangular snack box with removable snack pockets like this one on sale for $9.95 on Amazon (as of this writing). I know it sounds a little crazy. There are plenty of ways to snack and transport snacks. Why is this so much better? I have a theory.

What Is The Snackle Box?

Snackle Box 1 1

The Snackle Box is a verbal play on the tackle box, which most of you are probably familiar with from fishing with your dad. The difference is that this one isn’t filled with rusty lures designed to send you to the ER (sorry Dad). Instead, it’s filled with tasty snacks!

There are numerous variations out there, but it’s this specific one pictured above that I’m talking about. For some reason, the world has decided that the ideal configuration is a clear plastic rectangle that’s about 11.5″ x 8.5″ x 3″ with a removable, top clasping lid and vaguely beige coloring. Inside are eight equally-sized cups that can be removed and put in the dishwasher.

@jenniesuk

snack boxes on airplanes is the best idea ever ???????????? #snackbox #flighthacks #snackideas #snacklebox

♬ original sound – Ruthie21???? – ꧁ Ruthie ꧂

In the TikTok video above (or linked here) a woman got 6 million views for bringing one of these identical boxes on a plane with her. She went with a classic mix of sweet and salty treats with a double-load of goldfish crackers (she edits it out, but you can see she also put a folded-up paper towel under the lid, which is a pro-level move). I’ve only used the Snackle Box for sleepovers and road trips, but I get the appeal of taking it on a plane.

I know how this sounds. It sounds dumb. It sounds obvious. When the Snackle Box first appeared at my place I discounted it as another supposedly life-altering item that would end up shoved in a cabinet along with our Soda Stream and poach pocket. Friends, I was wrong.

Snackle Box 2 1

I’m not too big of a man to admit that. I’m not hangry about being wrong. In fact, I’m not hangry at all … on account of the access to snacks.

My Theory Of Why The Snackle Box Is So Hip

There are a few reasons why I think the Snackle Box has taken off on social media lately. My first theory is purely about commerce. Amazon and other retailers will pay, via a special link, if people buy a product you recommend. Everyone does this, from the New York Times all the way down to your aunt who has a podcast about herbivores. This post contains such a link and we do, sometimes, tag links (although rarely considering that much of our competition has whole sections devoted to it). This is something cheap so I imagine the real money is made on volume.

However, people recommend crap on the Internet all the time. Why, suddenly, is this popular? I think it’s because it actually works on a similar emotional level to what makes it work for social media algorithms.

The portability of the Snackle Box is high, but there are plenty of other snack containers that are even more easy to wield. The little pockets are supposedly dishwasher safe, though I wouldn’t put the outer plastic shell in there with your plates. I found this out the hard way when we deformed one of the lids.

I think the key to the Snackle Box is visibility. Its transparency is the magic piece here. It’s one thing to know that you’ve got a bag full of snacks, it’s another thing to see them all laid out like this. It makes every little shell of goodness in there look so appealing. In a way, the 4×2 grid mimics the grids on social media.

Snackle Box 2

Is it possible that our brains are so broken that we now see the whole world like Instagram or TikTok?

@brooklynrreidhead

roadtrip ready????????✨ these are so fun to make!! #asmr #asmrsounds #snacklebox #snacks #aesthetic #restock #asmrrestock #restockasmr #snackideas #foryou

♬ original sound – brooklyn reidhead

Probably!

The Snackle Box is also great if you have kids. You, as a normal adult, might be happy to have a bag of pretzels as a snack. Your kid is probably happier with three pretzels, six M&Ms, eight goldfish, one baby carrot, and 26 Nerds. Kids, whether at home or on a road trip, crave attention and variety. I’ve found that the Snackle Box has kept my daughter from asking for a snack every 18 seconds since she can get it for herself.

Also, I’m like an eight-year-old and I might be happy with one bag of Zappos, but I also would rather have a fun mix of salty and sweet.

Another perk of the boxes is that the size allows you to swap certain sections for items that are better left in their packages, like juice boxes and seaweed snacks:

Snackle Box 3 1

Those are Thin Mints btw. I’ve also experimented with shoving protein bars in there for long road trips so I’ve got something to keep me going.

Have you purchased one of these? What works best for you? If you haven’t, what would you put in these for your ideal road trip snack? Let’s get snackin’ folks.

The post The Snackle Box Has Revolutionized The Road Trip Snack Experience appeared first on The Autopian.

Read the whole story
LeMadChef
1 day ago
reply
Denver, CO
Share this story
Delete

Your doctor’s office could be reading your blood pressure all wrong

1 Share

Many people may be surprised to learn the proper procedure for taking a blood pressure reading—because of how different it is from what happens during their doctor's appointments.

According to the American Heart Association and other medical experts, getting an accurate reading requires following a strict set of preparations: You must not eat, drink, exercise, or smoke within 30 minutes of a reading. You must have an empty bladder. You must sit straight up in a chair with back support. Your legs must be uncrossed and your feet must be flat on the ground. The arm to be measured must be rested on a flat surface so that it is at the same level as your heart, not lower, not higher. You must sit calmly, without talking for five minutes to relax before the reading. When it's time, an appropriately sized cuff should be wrapped around your bare upper arm, right above the elbow; it should never be wrapped over clothing. At least two readings should be taken, with the average recorded. Ideally, readings should be taken in both arms, with the highest readings recorded.

Deviations from this protocol have the potential to significantly alter your blood pressure reading—and your blood pressure category. For instance, putting the blood pressure cuff over clothing can raise your reading as much as 50 mm Hg. That's enough to make someone with early stage hypertension seem as if they're in a hypertensive crisis, at imminent risk of a stroke or heart attack. If you have to pee, the reading can be 15 mm Hg higher. Talking can raise it by 10 mm Hg.

And, according to a new study in JAMA Internal Medicine, the all-too-common practice of having your arm in a position lower than your heart can raise your systolic blood pressure reading (the upper number) between 4- and 10-mm Hg. While those numbers may not seem dramatic, they're enough to push some patients over the edges of blood pressure categories. And these inaccurate readings are thought to happen often enough that they may lead to significant overdiagnosis of hypertension. In fact, the authors of the new study—led by researchers at Johns Hopkins—estimate that as many as 54 million people in the US may be misclassified as having hypertension simply because of the way their arm is positioned during readings.

Not using the correct arm position "has the potential to lead to substantial hypertension overdiagnosis, unnecessary patient follow-ups, and overtreatment," the authors conclude.

The study echoes previous data on inaccuracies from incorrect arm positions, but goes further by investigating the most common incorrect arm positions and using a gold-standard trial design.

For the study, researchers took blood pressure readings from 133 people with a mean age of 57 years. Each person had their blood pressure measured in four arm positions—with all other blood pressure reading preparations and positioning aligned with recommendations. The four arm positions were: one, with their arm properly resting on a desk (desk 1); two, with their arm incorrectly resting in their lap; three, with their arm incorrectly down at their side; and four, with their arm properly resting on a desk (desk 2). For each position, blood pressure readings were taken in triplicate, for a total of 12 readings from each person.

Under pressure

Before participants took readings in any of the positions, the researchers had them simulate walking into a doctor's appointment. They walked for two minutes and then sat calmly in position for five minutes before taking the three readings. Before moving onto the next position, they got up and walked again and sat for another five minutes. The participants were also randomized into groups that took the first three readings (desk 1, lap, side) in different orders, with all groups ending on desk 2.

The researchers then compared the differences between desk 1 and desk 2 to differences between lap and desk 1 and side and desk 1 for each participant. The desk 1-desk 2 differences captured intrinsic variability of blood pressure reading within each participant. The comparisons to lap-desk 1 and side-desk 1 captured changes based on the improper arm positions.

In all, there was little difference in the desk 1-desk 2 comparison, with participants having a mean difference of -0.21 mm Hg in systolic blood pressure and 0.09 in diastolic. But, the improper arm positions had significant effects on the readings. Lap arm position resulted in a mean increase of 4 mm Hg in both systolic and diastolic readings. Side arm position led to systolic readings that were 6.5 mm Hg higher and diastolic readings that were 4 mm Hg higher. For those with high blood pressure readings—about 36 percent of the participants—the wrong arm position caused yet higher readings, with systolic readings about 9 mm Hg higher than desk readings.

The authors speculate that simple physiological mechanisms likely explain the increase in blood pressure when the arm is lower than the heart—more gravitational pull, compensatory constriction of blood vessels, and muscle contraction may lead to higher pressure. As for why health care providers are known to sometimes use these wrong arm positions, it may be a lack of awareness, training, equipment, and/or resources.

The authors of the study call for more training and education about proper blood pressure measurements, which are essential for appropriate management of hypertension and prevention of cardiovascular disease.

Read full article

Comments



Read the whole story
LeMadChef
1 day ago
reply
Denver, CO
Share this story
Delete

Call Republican Supreme Court justices “Republicans” and not “conservatives” | Vox

Vox
1 Comment and 2 Shares

My more perceptive readers may have noticed that I’ve started referring to the justices of the Supreme Court as “Republicans” and “Democrats,” breaking with the traditional journalistic norm of labeling the justices “conservative” or “liberal.” In the interest of transparency, I want to explain why.

The short answer is that the words “Republican” and “Democrat” help convey what has happened to the Supreme Court in the last several decades. The Court has always been a political institution, but for most of its history there were not the hardline distinctions between justices chosen by a president of one political party, and justices chosen by the other party that we see today. As recently as 2010, for example, the Court included Justice John Paul Stevens, a Gerald Ford appointee who typically voted with the Court’s liberal wing.

Gone as well are relatively moderate jurists like Justices Lewis Powell, Sandra Day O’Connor, and Anthony Kennedy. These were the sorts of justices who voted to limit abortion rights, but not to eliminate them. They placed strict restrictions on affirmative action, but didn’t kill it entirely.

Now, however, this kind of moderation is anathema, especially to Republican legal elites, many of whom still use the battle cry “No More Souters” to describe their approach to judicial appointments — a reference to Justice David Souter, a George H.W. Bush appointee who turned out to be a moderate liberal.

The Republican Party’s highest officials certainly haven’t behaved as if they think that justices are nonpartisan. Why else would Senate Republican Leader Mitch McConnell make up a fake rule to stop President Barack Obama from confirming a Supreme Court justice in the final year of his presidency? McConnell claimed that justices may not be confirmed in a presidential election year. Then he abandoned this fake rule four years later to place Trump appointee Amy Coney Barrett on the high court.

Nor have Democrats failed to police their own nominees’ ideological conformity. None of the Supreme Court justices appointed by presidents Bill Clinton, Barack Obama, or Joe Biden broke with the Democratic Party’s approach to judging in the same way that Souter broke from the GOP’s. All of them generally supported abortion rights, affirmative action, marriage equality, and the Affordable Care Act. Every Democrat on the Supreme Court opposed Donald Trump’s claim that he could commit crimes while he was in office. All of the Court’s Democrats oppose the Republican justices’ decisions giving themselves a veto power over any regulatory decision made by the executive branch.

The word “conservative,” which is typically used to signal caution or an allegiance to the status quo, is a particularly inappropriate term to describe this Court’s Republican majority. What, exactly, are the Republican justices “conserving” when they overrule multiple seminal precedents in a single term? What is “conservative” about abandoning the Court’s procedural norms to hand down revolutionary new legal rules on the Court’s shadow docket? What is “conservative” about rushing out half-baked legal standards that are incomprehensible to lower court judges?

I am a journalist. That means it is my job to convey truth to my readers, and to describe the Court that I cover as accurately as I possibly can. And the unfortunate truth is that the Supreme Court of the United States is now a partisan institution. I would do my readers a disservice if I covered up this reality. Or if I used euphemistic language like “conservatives” and “liberals” to describe fundamentally partisan political appointees.

And so I will not. And I encourage other journalists to do the same.

It’s astonishing how little thought many past presidents put into their Supreme Court appointments. In the past, justices were often chosen for idiosyncratic personal reasons, or to please a particular interest group or voting bloc, and without much, if any, inquiry into how the nominee was likely to decide cases.

President Woodrow Wilson, for example, appointed Justice James Clark McReynolds — an awful judge and an even worse human being who Time magazine once described as a “savagely sarcastic, incredibly reactionary Puritan anti-Semite” — in large part because Wilson found McReynolds, who was US attorney general before he joined the Court, to be so obnoxious that the president promoted him to get him out of the Cabinet.

Similarly, President Dwight Eisenhower complained late in his presidency that appointing Justice William Brennan, one of the most consequential left-liberal jurists in American history, to the Supreme Court was among the biggest mistakes he made in office. But Ike’s White House never vetted Brennan for his ideological views, and Brennan was selected largely because Eisenhower was running for reelection when he made the nomination, and he thought that appointing a Catholic like Brennan would appeal to Catholic voters.

Even in 1990, after top Republican officials had published lengthy documents laying out their party’s vision for the Constitution, they still hadn’t developed a reliable system for vetting Supreme Court nominees to ensure that they were on board with the party’s agenda. Bush chose the center-left Justice Souter over other, more right-wing candidates largely due to misguided advice from his top legal advisers.

As journalist Jan Crawford Greenburg reported in a 2007 book, Souter beat out early frontrunner Ken Starr — the same Ken Starr who would go on to hound President Bill Clinton in the Monica Lewinsky investigation — in large part because Bush’s right-wing advisers feared that Starr was too liberal. According to Crawford Greenburg, then-Deputy Attorney General Bill Barr opposed Starr because of a low-stakes dispute over “a federal law that permitted private citizens to sue for fraud against the federal government.”

Much has changed since 1990. On the Republican side, the Federalist Society — a kind of bar association for right-wing lawyers with chapters on most law school campuses and in most major cities — now starts vetting law students for elite legal jobs almost as soon as they begin their studies. And Republican presidents can rely on the Federalist Society to identify ideologically reliable candidates for the bench. As Trump said in 2016 while campaigning for president, “We’re going to have great judges, conservative, all picked by the Federalist Society.”

Nor is the Federalist Society the only way Republicans vet potential Supreme Court nominees. Every single one of the Court’s current Republican members except for Barrett previously served as a political appointee in a GOP administration, roles that allowed high-level Republicans to observe their work and probe their views.

Democrats’ vetting process, meanwhile, is more informal. But it’s been no less successful in identifying Supreme Court nominees who reliably embrace their party’s stance on the most contentious issues. The last Democrat appointed to the Supreme Court who broke with the party’s pro-abortion rights stance, for example, was Justice Byron White — a dissenter in Roe v. Wade appointed by President John F. Kennedy in 1962.

The result is a modern-day Supreme Court where every single member was carefully selected by their party to ensure that they will not stray on any of the issues where the two parties have settled views. Every Republican justice voted to abolish affirmative action on nearly all university campuses, with every Democratic justice in dissent. Every Republican voted to give the leader of the Republican Party broad immunity from criminal prosecution, with every Democrat in dissent. Every Republican except for Roberts voted to overrule Roe (and Roberts merely argued that the Court should have waited a little longer), while every Democrat dissented.

So, with all this evidence that the Supreme Court has become no less partisan than Congress or the presidency, what are the arguments against speaking of the justices in the same way we speak of presidents or members of Congress?

Let’s start with the worst — albeit fairly common — argument for labeling the justices as nonpartisan actors: the claim that the justices are merely carrying out a particular “judicial philosophy” when they make decisions, and not making decisions based on what outcome their political party would prefer.

As a descriptive matter, it’s probably true that most of the justices imagine themselves as devotees to a particular philosophy of judging, rather than as partisans carrying out a predetermined agenda. The six Republican justices who ruled that Trump was allowed to do crimes while he was in office, for example, would probably claim that they were applying a legal theory known as the “unitary executive” when they ruled in Trump’s favor — and not that they were reflexively protecting their own party leader.

But this distinction is entirely academic, and it says nothing about how judges actually behave on the bench. As a practical matter, the difference between a hypothetical justice who consistently votes for the Republican Party’s preferred outcomes because they’ve adopted a “judicial philosophy” that reliably leads to those outcomes (we’ll call this hypothetical justice “Clarence Thomas”), and a hypothetical justice who votes for the same outcomes because they are a party loyalist (we’ll call this hypothetical justice “Samuel Alito”), is nonexistent.

A slightly more sophisticated rebuttal is that the Court’s Republicans often vote with the Court’s Democrats. This is especially true in cases that do not raise politically contentious issues, but it also occasionally happens in cases involving divisive issues such as abortion. As Sarah Isgur and Dean Jens argue in an early June article making this claim, in the Court’s 2022-23 term, “about 50 percent of the court’s cases were decided unanimously.”

It is true that the Court still hears a decent share of cases involving technical legal questions — such as when someone seeking certain veterans benefits should file a particular form, or when certain bankruptcy cases may be appealed — that do not divide the justices along partisan lines. But the same can be said about the other branches of government.

In the month of July alone, for example, Congress enacted, and President Joe Biden signed, 13 new laws. None of these laws divided the two parties, and all of them were passed overwhelmingly — in some cases by a voice vote or by unanimous consent. Yet political reporters have no problem with labeling members of Congress “Democrats” or “Republicans” even though those members frequently agree about which bills should become law.

Similarly, if you look at the schedule of, say, Florida Gov. Ron DeSantis, a Republican, you will find that it is dominated by the sort of ordinary governance issues that come before governors of either party. DeSantis recently awarded an $8 million grant to help build roads in a Miami park, for example. And he touted the fact that emergency responders in Florida “pumped more than 194 million gallons of floodwaters” from Florida communities hit by Hurricane Debby.

It’s likely that, if Florida’s governor was a Democrat, the state would have had a similar response to a hurricane. But the fact that DeSantis frequently oversees nonpartisan activity does not make him any less of a Republican.

It’s also true that the Supreme Court, despite its Republican majority, sometimes reverses lower court decisions that would have moved the law aggressively rightward. In its most recent term, the justices reversed several fairly extreme decisions from the far-right United States Court of Appeals for the Fifth Circuit, including one that could have triggered a second Great Depression.

But, again, the fact that the Republican justices do not always take maximally right-wing views does not make them less Republican. Nor does it distinguish them from Republicans in other parts of the government. Many GOP members of Congress, for example, oppose providing military aid to Ukraine. But, when a Ukraine aid bill finally reached the House and Senate floors this spring, it was supported by 101 Republican House members and 31 Republican senators.

Similarly, in 2023, DeSantis proposed unconstitutional legislation that would have limited press freedom in the state of Florida. Yet, while some Florida Republicans backed DeSantis, the bill died after conservative media organizations lobbied Republican lawmakers, warning them that the bill might hurt right-wing outlets.

It is entirely normal, in other words, for Republican officials to disagree about specific issues, even if they share a partisan identity and a general approach to governance. The fact that the Republican justices also sometimes disagree with each other, or with more extreme Republicans elsewhere in the judiciary, does not make them any less Republican.

The Republican justices, in other words, behave just like Republicans in other policymaking roles. They sometimes disagree with their fellow Republicans on important issues, but they also share a broad theory of governance, as well as a fairly granular agenda that includes (among other things) eliminating the constitutional right to an abortion, implementing a “colorblind” theory of the Constitution, and centralizing regulatory authority in the judicial branch of government.

This shared agenda, moreover, did not happen by coincidence. It happened because Republicans developed a coherent view of the Constitution and the role of the judiciary, and then built sophisticated institutions to ensure that their judicial appointees share this view.

Journalists do not hesitate to label, say, former Attorney General Bill Barr a “Republican” just because he was appointed to high office and not elected, and we should not treat the political appointees on the Supreme Court any differently. We should call the Republican justices “Republicans,” and the Democratic justices “Democrats,” because that is the best way to educate our readers about how the modern-day Supreme Court actually functions.

Read the whole story
LeMadChef
2 days ago
reply
Naah, I'm going to call them what they really are. Fascists.
Denver, CO
acdha
2 days ago
reply
Washington, DC
Share this story
Delete

A popular but wrong way to convert a string to uppercase or lowercase

3 Shares

It seems that a popular way of converting a string to uppercase or lowercase is to do it letter by letter.

std::wstring name;

std::transform(name.begin(), name.end(), name.begin(),
    std::tolower);

This is wrong for many reasons.

First of all, std::tolower is not an addressible function. This means, among other things, that you are not allowed to take the function’s address,¹ like we’re doing here when we pass a pointer to the function to std::transform. So we’ll have to use a lambda.

std::wstring name;

std::transform(name.begin(), name.end(), name.begin(),
    [](auto c) { return std::tolower(c); });

The next mistake is a copy-pasta: The code is using std::tolower to convert wide characters (wchar_t) even though std::tolower works only for narrow characters (even more restrictive than that: it works only for unsigned narrow characters unsigned char). There is no compile-time error because std::tolower accepts an int, and on most systems, wchar_t is implicitly promotable to int, so the compiler accepts the value without complaint even though over 99% of the potential values are out of range.

Even if we fix the code to use std::towlower:

std::wstring name;

std::transform(name.begin(), name.end(), name.begin(),
    [](auto c) { return std::towlower(c); });

it’s still wrong because it assumes that case mapping can be performed char-by-char or wchar_t-by-wchar_t in a context-free manner.

If the wchar_t encoding is UTF-16, then characters outside the basic multilingual plane (BMP) are represented by pairs of wchar_t values. For example, the Unicode character OLD HUNGARIAN CAPITAL LETTER A² (U+10C80) is represented by two UTF-16 code units: D803 followed by DC80.

Passing these two code units to towlower one at a time prevents towlower from understanding how they interact with each other. If you call towlower with DC80, it recognizes that you passed only half of a character, but it doesn’t know what the other half is, so it has to just shrug its shoulders and say, “Um, DC80?” Too bad, because the lowercase version of OLD HUNGARIAN CAPITAL LETTER A (U+10C80) is OLD HUNGARIAN SMALL LETTER A (U+10CC0), so it should have returned DCC0. Of course towlower doesn’t have psychic powers, so you can’t really expect it to have known that the DC80 was the partner of an unseen D803.

Another problem (which applies even if wchar_t is UTF-32) is that the uppercase and lowercase versions of a character might have different lengths. For example, LATIN SMALL LETTER SHARP S (“ß” U+00DF) uppercases to the two-character sequence “SS”:³ Straße ⇒ STRASSE, and LATIN SMALL LIGATURE FL (“fl” U+FB02) uppercases to the two-character sequence “FL”. In both examples, converting the string to uppercase causes the string to get longer. And in certain forms of the French language, capitalizing an accented character causes the accent to be dropped: à Paris ⇒ A PARIS. If the accented character à were encoded as LATIN SMALL LETTER A (U+0061) followed by COMBINING GRAVE ACCENT (U+0300), then converting to uppercase causes the string to get shorter.

Similar issues apply to the std::string version:

std::string name;

std::transform(name.begin(), name.end(), name.begin(),
    [](auto c) { return std::tolower(c); });

If the string potentially contains characters outside the 7-bit ASCII range, then this triggers undefined behavior when those characters are encountered. And for UTF-8 data, you have the same issues discussed before: Multibyte characters will not be converted properly, and it breaks for case mappings that alter string lengths.

Okay, so those are the problems. What’s the solution?

If you need to perform a case mapping on a string, you can use LCMap­String­Ex with LCMAP_LOWERCASE or LCMAP_UPPERCASE, possibly with other flags like LCMAP_LINGUISTIC_CASING. If you use the International Components for Unicode (ICU) library, you can use u_strToUpper and u_strToLower.

¹ The standard imposes this limitation because the implementation may need to add default function parameters, template default parameters, or overloads in order to accomplish the various requirements of the standard.

² I find it quaint that Unicode character names are ALL IN CAPITAL LETTERS, in case you need to put them in a Baudot telegram or something.

³ Under the pre-1996 rules, the ß can capitalize under certain conditions to “SZ”: Maßen ⇒ MASZEN. And in 2017, the Council for German Orthography (Rat für deutsche Rechtschreibung) permitted LATIN CAPITAL LETTER SHARP S (“ẞ” U+1E9E) to be used as a capital form of ß.

The post A popular but wrong way to convert a string to uppercase or lowercase appeared first on The Old New Thing.

Read the whole story
LeMadChef
2 days ago
reply
Denver, CO
Share this story
Delete
Next Page of Stories