ID:2146897
 
Code:
pos = findtextEx(newtext, "\"", lastposition) // we're searching for quotations


Problem description:

This always returns a 0. I'm guessing that means quotations aren't supported? I'm running this on an input, so there is always a quotation in the given text. If they aren't supported, are there any alternatives?
The simplest test succeeds:
mob/Login() src << findtextEx("1234\"678", "\"")

// outputs 5, as expected


The only problems could come from your newtext, lastposition, and your method of seeing that pos is 0.
In response to Kaiochao
Hm, I suppose I was wrong then. Here's the full bit, maybe you can see where I'm going wrong here.

        Emote(msg as text)
if(!msg) return
msg = "[html_encode(msg)]"
var whisper = 0
var range = VIEW_RANGE
if(dd_hassuffix(msg, "//"))
msg = dd_replacetext(msg, "//", "")
whisper = 1
range = WHISPER
var newtext = msg // this holds our updated text
if(EmoteDiaToggle)
var nth = 0 // checks for even and odd on the " check
var notdone = 1
var lastposition = 1
var pos = 1 // this records what our findtext search looks for
var append // for switching between an opening and closing tag
var lentextadd = 0
while(notdone)
pos = findtextEx(newtext, "\"", lastposition) // we're searching for quotations
lastposition = pos + 1
if(!pos) break
if(nth % 2 == 0) append = "<font color='#fff'>"
else append = "</font>"
lentextadd = lentext(append)
lastposition += lentextadd
newtext = "[copytext(newtext, 1, pos)][append][copytext(newtext, pos)]"
nth = !nth // inverse the boolean value
var/output = "<font color='[TextColor]'>[name] [newtext]</font>"
icOut(src, output, range) // we leave out the range so it defaults
if(whisper) icOutMinus(src, "<font color='[TextColor]'>[name] does something secretly.</font>", VIEW_RANGE, range)
It looks like you're trying to add special formatting to text between quotation marks. I don't have the patience to read through your implementation attempt, so here's what I came up with:
proc
replace_quotes(Text, Open, Close)
var
const/QUOTATION_MARK = "\""
is_open = FALSE
position = 0
last_start
result = ""
for()
last_start = position + 1
position = findtextEx(Text, QUOTATION_MARK, last_start)
if(!position)
return "[result][copytext(Text, last_start)]"
else if(copytext(Text, position - 1, position) == "\\")
result = "[result][copytext(Text, last_start, position - 1)]\""
else
#if DM_VERSION >= 511
result = "[result][copytext(Text, last_start, position)][(is_open = !is_open) ? Open : Close]"
#else
is_open = !is_open
result = "[result][copytext(Text, last_start, position)][is_open ? Open : Close]"
#endif

Example usage: add a font tag after open-quotes and an end tag before close-quotes.
msg = replace_quotes(msg, "\"<font color=#fff>", "</font>\"")
Nice work. I haven't tested it yet, because there are a couple things I'm not understanding. Whats up with the backslashes?
regeeeeeex

/proc/replace_quotes(text, open, close)
return replacetext(text, regex("\"(\[^\"\]*)\"", "g"), "[open]$1[close]")

/world/New()
world.log << replace_quotes("foo \"bar\" testing \"baz\".", "\"<font color=#fff>", "</font>\"")
// ^^^ prints: foo "<font color=#fff>bar</font>" testing "<font color=#fff>baz</font>".
In response to Kitsueki
Which backslashes?

\" is used to insert a double-quote into a string. You probably already knew that.

\\ is used to insert a single backslash into a string. This is used in my replace_quotes() to allow for escaped quotes that shouldn't be affected... I'm not sure why I included that functionality. Also, I accidentally left in the backslash, so I edited the code to fix that.
In response to GinjaNinja32
Nice! I considered using regex, and then gave up too quickly.

Might as well move that regex to a global var in the proc so it's not created more than once.
Just doesn't seem to be working for me. I've been trying to debug it as much as I can but nothing seems to fix it.

proc
replace_quotations(text, open, close)
if(!text || !open || !close) return
var
const/quotation = "\""
is_open = FALSE
position = 0
last_start
result = ""
for()
last_start = position + 1
position = findtext(text, quotation, last_start)
if(!position)
return "[result][copytext(text, last_start)]"
else if(copytext(text, position - 1, position) == "\\")
result = "[result][copytext(text, last_start, position + 1)]"
else
is_open = !is_open
result = "[result][copytext(text, last_start, position)][is_open ? open : close]"

// then I call...

if(EmoteDiaToggle) msg = replace_quotations(msg, "\"<font color='#fff'>", "</font>\"")
In response to GinjaNinja32
Thinking about it, but I haven't messed with regexs in years, changing this up later would be a pain until I learn them, lmao.
In response to Kitsueki
Both my code and your version of my code are working perfectly, according to my test:
mob/Login() src << replace_quotes("A \"B\" C", "\"<font color='#fff'>", "</font>\"")

The problem must be elsewhere in your code, e.g. EmoteDiaToggle is false.
Just double checked, that variable is set to 1 / TRUE. I even tried the regex. No idea why this isn't working for me. I can share the project if you feel like taking a look at it.

Edit: I should probably say, the project is fresh, so you wont have to sift through tons of code
In response to Kitsueki
What's the Emote verb look like now? Are you actually outputting the text that had quotations replaced?
In response to Kaiochao
Yeah, when I try that specific text it seems to be working just fine :S

        Emote(msg as text)
if(!msg) return
msg = "[html_encode(msg)]"
var whisper = 0
var range = VIEW_RANGE
if(dd_hassuffix(msg, "//"))
msg = dd_replacetext(msg, "//", "")
whisper = 1
range = WHISPER
if(EmoteDiaToggle) msg = replace_quotations(msg, "\"<font color='#fff'>", "</font>\"")
var/output = "<font color='[TextColor]'>[name] [msg]</font>"
icOut(src, output, range) // we leave out the range so it defaults
if(whisper) icOutMinus(src, "<font color='[TextColor]'>[name] does something secretly.</font>", VIEW_RANGE, range)
proc/replaceSeg(string,start,end)
var a,b
while(findtext(string,"\""))
a = findtext(string,"\"")
b = findtext(string,"\"",a+1)
if(b) string = copytext(string,1,a) + "[start]|&[copytext(string,a+1,b)]|&[end]" + copytext(string,b+1)
else break
string = replacetext(string,"|&","\"")
return string


mob/verb/Demo()
var string = "Kozuma says \"Hello!\""
src << string
src << replaceSeg(string,"<i>","</i>")

From your first post,
I'm running this on an input, so there is always a quotation in the given text.

There isn't always a quotation in text. When you call a verb from the input bar that takes text as an argument, the text itself is usually wrapped in quotation marks (if text is the only argument, the quotation marks are optional). This doesn't mean the text itself contains quotation marks, though.

For example,
say Hello World
say "Hello World"
Both are valid ways of using a verb like this:
client/verb/say(T as text)

But in both cases, T does not actually contain any quotation marks.

I was using your emote verb like this:
Emote A "B" C
and like this:
Emote "A "B" C"
and it was correctly formatting the B as it should, and nothing else.
In response to Kaiochao
Yeah, I get you. I'm using the popup input, and I'll type something in like a "B" c, or whatever arbitrary thing I can think of that includes a few quotation marks. It doesn't work with that.

If it's working for you, I wonder what's going on then..