根据 CamelCase 来分割字符串

for $=finish.lines -> $word {
    say ($word.comb: /+/)».lc.join("_");
}


=finish
HelloWorld
CamelCase
RakudoStar

输出:

hello_world
camel_case
rakudo_star

One More Example:

for $=finish.lines -> $line {
    my ($field, $type) = $line.split: /',' \s+/;

    if $field.contains('_') { # 如果包含下划线则进行分割
        my @words = $field.split('_');

        # 遍历 words 中的所有单词
        my @w = gather for @words -> $word {
            if all($word.comb) (elem) 'A'..'Z' { # 如果这个单词都是大写字母
                take $word.lc; # 转成小写字母并 take
            } else {
                # 如果是 CamelCase 这样的单词, 就 comb
                take ($word.comb: /+/).».lc.join('_');
            }
        }
        say sprintf("`%s` %s,", @w.join('_'),  $type);
    } else { # 否则直接打印
        say sprintf("`%s` %s", $field, $type);
    }
}

=finish
vin, string
updatetime, bigint
timestamp, bigint
TEL_Time_Sec, int
TEL_Time_Min, int
TEL_Time_Day, int
TEL_Time_Hour, int
TEL_Time_Month, int
TEL_Time_Year, int
BCM_PsngrDoorAjarSt, int
BCM_DriverDoorAjarSt, int
ICM_AvaibleDriveDistance, int
BMS_CellVoltMin, float
BMS_CellVoltMax, float
BMS_OBC_ChgCurrMax, float
BMS_OBC_ChgVoltMax, float
BMS_FaultLampInd, int
BMS_ErrLvl, int
BMS_DcChgErrLvl, int
VCU_VehElcConspAvg, float
HVAC_DriverTempSelect, float
SRS_AirbagFaultSt, int
SRS_DriverSeatBeltSt, int
SRS_PsngrSeatBeltSt, int
TGW_FaultLampInd, int
TGW_WaterPump2EnErr, int
TGW_WaterPump2SpdErr, int
TGW_EmValveErr, int
TGW_3To2ValveErr, int
TGW_WaterPump1EnErr, int
TGW_WaterPump1SpdErr, int
TGW_ExterTemp, int
TGW_BattTemp2, int
TGW_BattTemp1, int
TGW_WaterPump2Info, int
TGW_WaterPump1Info, int
DCU_CurrAct, int
TGW_HVPTCSt, int
DCU_VoltAct, int
TGW_HVPTCHVVoltage, int
TGW_HVPTCHVDCCurr, float
DCU_MotTempAct, int
DCU_InvtTempAct, int
DCU_FaultLampInd, int
DCU_ErrLvl, int
DCU_ModeSt, int
IPS_OBCCC_Cap, int
IPS_OBCCP_Voltage, float
IPS_OBCCp_S2_State, int
IPS_OBCCp_DutyCycle, int
IPS_OBCFaultLampInd, int
IPS_OBCCp_FrequencyState, int
IPS_OBCCP_State, int
IPS_OBCHvDcVoltAct, int
IPS_OBCUacActL1, int
IPS_OBCHvDcCurrAct, float
IPS_OBCCurrActL1, float
IPS_OBCCC_State, int
IPS_OBCTempAct, int
IPS_OBCModeSt, int
IPS_DCDCFaultLampInd, int
IPS_DCDCModeSt, int
IPS_DCDCErrLvl, int
IPS_DCDCVoltLvAct, float
IPS_DCDCVoltHvAct, int
IPS_DCDCCurrLvAct, int
IPS_DCDCCurrHvAct, float
IPS_DCDCTempAct, int
BMS_InslRes, int
BMS_BattSoc, float
BMS_BattVolt, int
BMS_OBC_SlpCtrl, int
BMS_OBC_AtvCtrl, int
BMS_BattCurr, float
BMS_BattSt, int
BMS_CellTempMin, int
BMS_CellTempMax, int
VCU_EMS_BrkPedalSt, int
BCM_KeySt, int
HVAC_ECPPwrConsump, int
HVAC_PTCPwrConsmp, int
HVAC_PTCFault, int
HVAC_ECPFault, int
HVAC_AirCirculationSt, int
BCS_VehSpd, float
BMS_DcChargerSt, int
BMS_BattChgErr, int
VCU_GearLvlDisp, int
VCU_VehElcConspAccumAvg, float
VCU_CrntGearLvl, int
VCU_HVACPwrLimitAct, int
VCU_TGW_WaterPump2En, int
VCU_TGW_EmValveEn, int
VCU_TGW_3To2ValveEn, int
VCU_TGW_WaterPump1En, int
VCU_BattCoolCompressorPwrReq, int
VCU_VehChgSt, int
VCU_ElcSysErr, int
HVAC_Type, int
IPS_OBCFault, int
VCU_VehDrvMod, int
VCU_HVACPwrLimit, int
VCU_PwrRqMode, int
VCU_WaterTemp2, int
VCU_TGW_WaterPump1SpdSet, float
VCU_EMS_AccPedalActPst, float
VCU_TGW_WaterPump2SpdSet, float
VCU_BrkPedSt, float
DCU_RotSpdAct, int
TEL_GPSAltitude, float
TEL_GPSSpeed, float
TEL_GPSDirection, float
TEL_AltitudeType, int
TEL_HomeInd, int
TEL_LongitudeMode, int
TEL_LatitudeMode, int
TEL_LocType, int
TEL_NaviPstVD, int
TEL_LongitudeSec, float
TEL_LongitudeMin, int
TEL_LongitudeDeg, int
TEL_LatitudeSec, float
TEL_LatitudeMin, int
TEL_LatitudeDeg, int
DCU_TorqAct, int
SAS_SteeringAngle, float
BCS_VehLongAccelOffset, double
BCS_YawRateOffset, double
BCS_YawRate, double
BCS_ActVehLongAccel, double
BCS_VehLaltrlAccelOffset, double
BCS_ActVehLaltrlAccel, double
ICM_TotalOdometer, int
SAS_SteeringAngleSpd, int

你可能感兴趣的:(根据 CamelCase 来分割字符串)