Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 7th June 2017, 20:47   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,201
StrFmt v1.00 - 14 Jan 2019

StrFmt() + StrRep().
Requires VS2008 CPP Runtimes.

dll's for avs v2.58 & avs/+ v2.60 x86 & x64.

Simple plugin to produce formatted string, and additional function to string replace with another string.

Code:
StrFmt(String format, dat1,...,datn)

 dll's for avs v2.58 & v2.60 x86 & x64.

 Returns a formatted string. The unnamed 'format' string and optional unnamed 'dat' args are used to construct the text string that is
 returned, uses C/CPP printf() style formatting.
 Format: compulsory string controlling format and describing the datn type args that are expected.
 datn: Variable number of data args of any type (excluding clip).

 printf Format spec here:- http://msdn.microsoft.com/en-us/library/56e442dc%28v=vs.71%29.aspx
  NOTE, the only support for printing Bool variables is %s as string, ie prints "True" or "False".

 Formatting supported, %[flags] [width] [.precision] type

  flags, one of  "-,+,0, ,#"
  width, integer, "*" supported (width supplied via dat arg).
  Precision, integer, "*" supported (precision supplied via dat arg).
  type,
    "c,C,d,i,o,u,x,X",  Integer type, c,C=character, d,i=signed, o,u,x,X=unsigned (o=octal, x=Hex).
    "e,E,f,g,G",        Floating point type
    "s,S",              String type (also Bool).

  Formatting Insertion point is marked with '%' character in the format string (as in Avisynth String function), if you wish to use
  a percent character within the returned string, it should be inserted twice in the format string ie '%%' will produce a single '%'.
  The data datn arg strings do not require a double '%' character.

  A Backslash character '\' introduces escape sequences, to insert a backslash character itself, you must supply a double
  backslash sequence ie '\\'.
  Converts embedded escape character sequences (Case Significant):-
    '\\' Converted to '\'       Single Backslash
    '\n' Converted to Chr(10)   NewLine
    '\r' Converted to Chr(13)   Carriage Return
    '\t' Converted to Chr(9)    Horizontal TAB
    '\v' Converted to Chr(11)   Vertical TAB
    '\f' Converted to Chr(12)   FormFeed
    '\b' Converted to Chr(8)    BackSpace
    '\a' Converted to Chr(7)    Bell
    '\x', where x is ANY OTHER CHARACTER not included above, will be copied verbatim, ie '\x'.

  eg
   StrFmt("Hello there %s and %s.\nGoodbye %d.","Fred","Ted",2019)
   would return same as:-   "Hello there Fred and Ted." + Chr(10) + "Goodbye 2019."

*****
*****
*****

StrRep(string source,string find,string replace,bool "sig"=True)   # Based on Algorithm by Vampiredom, Gavino & IanB.

 String args 'source', 'find' and 'replace' unnamed and compulsory.
 Takes a source string, searches for all occurences of find string and replaces the found strings with the replace string.
 Can use "" in replace string (only in replace) to delete the found substrings from the source string.
 Newlines [Chr(10)] are treated no differently to other characters, and could be replaced/deleted.
 'sig' arg,default true is Case Significant. Set false for case insignificant find string.

Test1
Code:
colorbars.killaudio
S = StrFmt("'%0*.*f'",10,3,9999.99)
Subtitle(S) # print '009999.990', ie total length of digits and '.' is 10, with 3 significant fractional digits. 

# EDIT: the '0' after '%' uses '0' characters for leading zero padding instead of SPACE's
# EDIT: And the two '*' in format string, are where the 10 and 3 data args are inserted for Width and Precision specifiers. [ie script programmable Width & Precision rather than fixed format]
Test2
Code:
S="The Cat sat on the mat"

CASESIG=False

S2=StrRep(S,"cat","bat",CASESIG)

ColorBars.killAudio
Subtitle(S2) # print "The bat sat on the mat"
Equivalent functions in RT_Stats, RT_String and RT_StrReplace.

zip (~72KB) incl 3 dll's + source + VS2008 full project files for easy rebuild.

See MediaFire in sig below this post, or SendSpace.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 16th January 2019 at 13:06. Reason: Update
StainlessS is offline   Reply With Quote
Old 9th June 2017, 21:00   #2  |  Link
amayra
Quality Checker
 
amayra's Avatar
 
Join Date: Aug 2013
Posts: 227
this looks very interesting thanks
__________________
I love Doom9
amayra is offline   Reply With Quote
Old 9th June 2017, 23:47   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,201
Glad you like it

StrFmt() provides a very powerful string generator, much better than the basic Avisynth String() function, (which is a little bit
clumsy to use when more than a very simple string with numeric).

And here the thread that seems to introduce the StrReplace() function, way back when:- https://forum.doom9.org/showthread.p...ce#post1540487
The dll version will save on memory usage as it creates no temporary intermediary strings (only pertinent where lots and lots of strings replaced).

EDIT: Note also that the width and precision specifiers also work with strings, eg
StrFmt("%5s","Fred") would print " Fred", and [string width=5 example ie '%5s']
StrFmt("%.1s",True) would print "T". [string precision=1 example, ie '%.1s']
Width is the minimum length of generated string [EDIT: for strings includes SPACE padding], precision is the maximum length of generated string [EDIT: for strings, non padded length] .
And can left justify, eg StrFmt("%-5s","Fred") would print "Fred ".
And can also use Width specifier programmatically, eg,
Code:
n=5
StrFmt("%-*s",n,"Fred") # would produce "Fred ". ["Fred" + 1 SPACE], = length of 5 characters, left justified.
or

Code:
n=6
B = True
StrFmt("%-*s",n,B) # would produce "True  " [2 SPACES] when B=True, and "False " [1 SPACE] when B=False.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 15th January 2019 at 01:08.
StainlessS is offline   Reply With Quote
Old 29th July 2017, 23:24   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,201
Bug fix update, v0.01.
Mods in BLUE (was printing character from buffer after buffer released).
Code:
    int tmpc=*r;
    delete [] pbuf;
    env->ThrowError("%sType='%c', Expecting Int data (%d)",myName,tmpc,ix+1);					}
EDIT: Turns out that above bug was not a bug at all, first time in my life that I've fixed a non existing bug (No idea what I was thinking)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th November 2017 at 22:09.
StainlessS is offline   Reply With Quote
Old 15th January 2019, 00:52   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,201
StrFmt() v1.00, update, see 1st post.

Moved to VS2008, Added Version Resource, added avs/+ v2.60 x86 & x64 dll's. (as well as 2.58 dll)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Reply

Tags
replace, string

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:54.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.