<?xml version="1.0" encoding="UTF-8"?>
<rename_preset case="none" group="大小写" preset="Titlecase (Opus 12)" script="yes" type="normal" version="12">
	<from>*</from>
	<to>*</to>
	<script>@script vbscript
Option Explicit
&apos; ********************************************************
&apos;  TitleCase by Steve Banham (tanis@dopus.com) 07-Apr-2007
&apos;  Enhanced for Opus 12 by Leo Davidson, 31-Aug-2017
&apos; ********************************************************

Function OnGetCustomFields(getFieldData)

	&apos; Define checkboxes and initial states
	getFieldData.fields.fOddChars    = True &apos; Replace %20 with spaces
	getFieldData.fields.fUnderscore  = True &apos; Replace &quot;_&quot; with a space
	getFieldData.fields.fMultiSpace  = True &apos; Remove multiple spaces
	getFieldData.fields.fExtLCase    = True &apos; Make extension lower case
	getFieldData.fields.fTitleCase   = True &apos; Convert to true titlecase
	getFieldData.fields.fParCap      = True &apos; Capitalise after parenthesis
	getFieldData.fields.fDashCap     = True &apos; Capitalise after a dash
	getFieldData.fields.fFullStopCap = True &apos; Capitalise after a full stop
	getFieldData.fields.fFirstNonNum = True	&apos; Capitalise first non-numeric


	&apos; Set the labels for the checkboxes
	getFieldData.field_labels(&quot;fOddChars&quot;)    = &quot;替换 &quot;&quot;%20&quot;&quot; 为空格&quot;
	getFieldData.field_labels(&quot;fUnderscore&quot;)  = &quot;替换 &quot;&quot;_&quot;&quot; 为空格&quot;
	getFieldData.field_labels(&quot;fMultiSpace&quot;)  = &quot;删除多个空格&quot;
	getFieldData.field_labels(&quot;fExtLCase&quot;)    = &quot;将扩展名改为小写&quot;
	getFieldData.field_labels(&quot;fTitleCase&quot;)   = &quot;转换成标题大小写 Title Case&quot;
	getFieldData.field_labels(&quot;fParCap&quot;)      = &quot;Title Case: 在括号后大写&quot;
	getFieldData.field_labels(&quot;fDashCap&quot;)     = &quot;Title Case: 在破折号dash&quot;&quot;-&quot;&quot;后大写&quot;
	getFieldData.field_labels(&quot;fFullStopCap&quot;) = &quot;Title Case: 在句号后大写&quot;
	getFieldData.field_labels(&quot;fFirstNonNum&quot;) = &quot;Title Case: 将第一个非数字大写&quot;

End Function

Function OnGetNewName(ByRef getNewNameData)

	dim strExt
	dim strNewName
	dim iOldLength
	dim iNewLength
	dim strNameArray
	dim strTmpWord
	dim strTmpName
	dim x
	dim j
	dim i

	&apos;Strip the filename extension for now
	strNewName = getNewNameData.newname_stem_m
	strExt = getNewNameData.newname_ext_m

	&apos; Make extension lower case
	if getNewNameData.custom.fExtLCase then
		strExt = LCase(strExt)
	end if

	&apos; Replace &quot;_&quot; with spaces
	if getNewNameData.custom.fUnderscore then
		strNewName = Replace(strNewName, &quot;_&quot;, &quot; &quot;)
	end if
	
	&apos; Replace &quot;%20&quot; with spaces
	if getNewNameData.custom.fOddChars then
		strNewName = Replace(strNewName, &quot;%20&quot;,&quot; &quot;)
	end if
	
	&apos; Remove all multiple spaces
	if getNewNameData.custom.fMultiSpace then
		iNewLength = 0
		iOldLength = len(strNewName)
		Do While iOldLength &gt; iNewLength
			iOldLength = len(strNewName)
			strNewName = Replace(strNewName,&quot;  &quot;,&quot; &quot;)
			iNewLength = len(strNewName)
		Loop
	end if

	&apos; Trim spaces at start/end of filename (e.g. because it used to start with a an underscore)
	&apos; If this is not done, the split function below may throw an error.
	strNewName = Trim(strNewName)

	&apos; Convert filename to TitleCase
	if getNewNameData.custom.fTitleCase then
		&apos; Create an array from words in the filename
		strNameArray = split(strNewName, &quot; &quot;)

		&apos; Now go through each item in the array and process it
		if ubound(strNameArray) &gt; 0 then
			for x = lbound(strNameArray) to ubound(strNameArray)
	
				&apos; Set all text to lower case to begin with
				strNameArray(x) = LCase(strNameArray(x))

				&apos; Ignore articles, prepositions and conjunctions
				Select Case strNameArray(x)
					Case &quot;a&quot;
					Case &quot;an&quot;
					Case &quot;at&quot;
					Case &quot;and&quot;
					Case &quot;but&quot;
					Case &quot;by&quot;
					Case &quot;for&quot;
					Case &quot;in&quot;
					Case &quot;into&quot;
					Case &quot;is&quot;
					Case &quot;of&quot;
					Case &quot;off&quot;
					Case &quot;on&quot;
					Case &quot;onto&quot;
					Case &quot;or&quot;
					Case &quot;the&quot;
					Case &quot;to&quot;
					Case &quot;it&quot;
					Case else
						if len(strNameArray(x)) &gt; 0 then

							strTmpWord = Ucase(mid(strNameArray(x),1,1)) &amp; mid(strNameArray(x),2,len(strNameArray(x))-1)

							&apos; If the word begins with &quot;(&quot; then capitalise the next letter
							if mid(strNameArray(x),1,1) = &quot;(&quot; then
								if getNewNameData.custom.fParCap then
									strTmpWord = Ucase(mid(strNameArray(x),1,2)) &amp; mid(strNameArray(x),3,len(strNameArray(x))-1)
								end if
							end if
							
							&apos; If the word follows a &quot;-&quot; then it needs to be capitalised
							if mid(strNameArray(x),1,1) = &quot;-&quot; then
								if getNewNameData.custom.fDashCap then
									strTmpWord = Ucase(mid(strNameArray(x),1,2)) &amp; mid(strNameArray(x),3,len(strNameArray(x))-1)
								end if
							end if

							strNameArray(x) = strTmpWord
						end if
				end Select
			next
		Else
			strNameArray(0) = LCase(strNameArray(0))
		End if

		&apos; Make sure the first word is capitalised
		strTmpWord = Ucase(mid(strNameArray(0),1,1)) &amp; mid(strNameArray(0),2,len(strNameArray(0))-1)
		strNameArray(0) = strTmpWord

		&apos; Clear the new name variable
		strNewName = &quot;&quot;

		&apos; Rebuild the array into one string
		For x = lbound(strNameArray) To ubound(strNameArray)
			strNewName = strNewName &amp; strNameArray(x) &amp; &quot; &quot;
		Next

		&apos; Capitalise after - when it&apos;s in the middle of words
		&apos; Capitalise after - when it&apos;s between words
		if getNewNameData.custom.fDashCap then
			For j = 1 to len(strNewName)
				if mid(strNewName,j,1) = &quot;-&quot; then
					strTmpName = strTmpName &amp; mid(strNewName,j,1)
					j=j+1
					if mid(strNewName,j,1) = &quot; &quot; then
						strTmpName = strTmpName &amp; mid(strNewName,j,1)
						j=j+1
					end if
					strTmpName = StrTmpName &amp; Ucase(mid(strNewName,j,1))			
				else
					strTmpName = strTmpName &amp; mid(strNewName,j,1)
				end if
			Next
			strNewName = strTmpName
			strTmpName = &quot;&quot;
		end if			

		&apos; Capitalise after full stops in the middle of and between words
		if getNewNameData.custom.fFullStopCap then
			For i = 1 To len(strNewName)
				if mid(strNewName,i,1) = &quot;.&quot; then
					strTmpName = strTmpName &amp; mid(strNewName,i,1)
					i=i+1
					if mid(strNewName,i,1) = &quot; &quot; then
						strTmpName = strTmpName &amp; mid(strNewName,i,1)
						i=i+1
					end if
					strTmpName = StrTmpName &amp; Ucase(mid(strNewName,i,1))			
				else
					strTmpName = strTmpName &amp; mid(strNewName,i,1)
				end if
			Next
			strNewName = strTmpName
			strTmpName = &quot;&quot;
		end if

		&apos; Capitalise first non-numeric, non-space character.
      		&apos; This is for music files like &quot;07 By My Side.flac&quot; which don&apos;t have a dash after their track numbers.
		if getNewNameData.custom.fFirstNonNum then
			For i = 1 to len(strNewName)
         			if (not IsNumeric(mid(strNewName,i,1))) and mid(strNewName,i,1) &lt;&gt; &quot; &quot; then
            				strNewName = mid(strNewName,1,i-1) &amp; Ucase(mid(strNewName,i,1)) &amp; mid(strNewName,i+1)
            				exit for
         			end if
      			Next
		end if
	end if
	
	&apos; Strip leading/trailing spaces
	strExt = Trim(strExt)
	strNewName = Trim(strNewName)
	
	&apos; Rejoin the name and extension and we&apos;re finished
	strNewName = strNewName &amp; strExt

	OnGetNewName = strNewName

End Function
</script>
</rename_preset>
