Playnite Forums
[ON HOLD] DeCamelCase (partly solved, will update thread later) - Printable Version

+- Playnite Forums (https://playnite.link/forum)
+-- Forum: Development (https://playnite.link/forum/forum-10.html)
+--- Forum: Extensions (https://playnite.link/forum/forum-5.html)
+--- Thread: [ON HOLD] DeCamelCase (partly solved, will update thread later) (/thread-1418.html)



[ON HOLD] DeCamelCase (partly solved, will update thread later) - OneAngryGamer - 05-04-2023

I have been working on a DeCamelCase function for metadata use. While it is working OK for most test values, I still have some input values that I want it to be able to convert.

I am sharing the function below.

The first block comment contains the list of values that I want the function to be able to convert.

Appreciate any help.

function Convert-DeCamelCase($value) {
#updated 20230425

<# NOT CONVERTING CORRECTLY
ActionRPG
BigNO
BrandX
ChekhovMIA
ClusterFBomb
HehHehYouSaidX
HellishLA
HeroicBSOD
HowDidYouKnowIDidnt
ImpendingDoomPOV
MagicAIsMagicA
MissXPun
NoFlowInCGI
NoOSHACompliance
NonLethalKO
OneHitKO
PrecisionFStrike
PressXToDie
PressXToNotDie
RatedMForManly
RefugeeFromTVLand
SlidingScaleOfLinearityVSOpenness
SpellMyNameWithAnS
TheXOfY
ThirdIs3D
VideoGame3DLeap
VillainousBSOD
WetwareCPU
XCalledTheyWantTheirYBack
YearX
YouCalledMeXItMustBeSerious
YouRemindMeOfX
#>

    $value = $value -csplit '(?<!^)(?=[A-Z][a-z])' -ne '' -join ' '

    # fix exceptions for surnames
    $value = $value -creplace 'Mac ','Mac'
    $value = $value -creplace 'Mc ','Mc'

    $value = $value -creplace 'O Vision','-O-Vision'


    if ($value -cmatch ' The[0-9]') {
        $value = $value -creplace 'The','The '
    }

    if ($value -cmatch '[a-z]I ') {
        $value = $value -creplace 'I ',' I '
    }
    if ($value -cmatch '[a-z]A ') {
        $value = $value -creplace 'A ',' A '
    }

    if ($value -cmatch '[a-z]AI') {
        #$value = $value -creplace 'AI',' A.I.'
        $value = $value -creplace 'AI',' AI'
    }


    # fix common apostrophe contractions
    $value = $value -creplace 'Shes ',"She's "
    $value = $value -creplace 'Hes ',"He's "
    $value = $value -creplace 'Youre ',"You're "
    $value = $value -creplace 'eres ',"ere's "
    $value = $value -creplace 'Dont ',"Don't "
    $value = $value -creplace 'dnt',"dn't"
    $value = $value -creplace 'Theyre ',"They're "
    $value = $value -creplace 'Youve ',"You've "
    $value = $value -creplace 'snt ',"sn't "
    $value = $value -creplace 'Im ',"I'm "
    $value = $value -creplace 'Thats ',"That's "

    # blindly adding apostrophe to 'Its' can result in incorrect usage
    $value = $value -creplace 'Its ',"It's "

    $value = $value.replace('  ',' ')

    return $value
}



RE: Help Needed - DeCamelCase - OneAngryGamer - 05-17-2023

The code had a copy/paste error. Fixed.

Anyone have any suggestions on how to improve this function?

I don't care about fixing acronyms. For input 'ChekhovMIA', I would want the function to return 'Chekhov MIA'. 'Heroic BSOD' returned from input 'HeroicBSOD' and so on.