Exemplo n.º 1
0
JBoolean
JSplitPathAndName
	(
	const JCharacter*	fullName,
	JString*			path,
	JString*			name
	)
{
	assert( !JStringEmpty(fullName) );

	JString pathAndName = fullName;
	assert( pathAndName.GetLastCharacter() != ACE_DIRECTORY_SEPARATOR_CHAR );

	JIndex i;
	if (pathAndName.LocateLastSubstring(ACE_DIRECTORY_SEPARATOR_STR, &i))
		{
		*path = pathAndName.GetSubstring(1,i);
		*name = pathAndName.GetSubstring(i+1, pathAndName.GetLength());

		JCleanPath(path);
		return kJTrue;
		}
	else
		{
		*path = JGetCurrentDirectory();
		*name = pathAndName;
		return kJFalse;
		}
}
void
GMMIMEParser::ParseContentDisposition
	(
	const JString&	val,
	GMIMEHeader*	header
	)
{
	// we first need to strip the type. this will be found before the
	// first ';' which will be followed by the parameters.
	JString tVal	= val;
	tVal.TrimWhitespace();
	JSize length	= tVal.GetLength();

	JIndex findex;
	if (tVal.LocateSubstring(";", &findex) && (findex > 1))
		{
		tVal.RemoveSubstring(1, findex);
		tVal.TrimWhitespace();
		}
	else
		{
		return;
		}

	JPtrArray<JString> strings(JPtrArrayT::kDeleteAll);
	ParseContentParameters(tVal, &strings);
	JSize count = strings.GetElementCount();
	for (JIndex i = 1; i <= count; i += 2)
		{
		JString* str = strings.NthElement(i);
		if ((*str == "filename") &&
			(strings.IndexValid(i+1)))
			{
			str	= strings.NthElement(i+1);
			if (str->LocateLastSubstring("/", &findex))
				{
				str->RemoveSubstring(1, findex);
				}
			if (str->LocateLastSubstring("\\", &findex))
				{
				str->RemoveSubstring(1, findex);
				}
			header->SetFileName(*str);
			}
		}
}
JBoolean
GMMIMEParser::GetTextSegment
	(
	const JIndex	index,
	JString*		text,
	TextFormat*		format,
	JString*		charset
	)
{
	assert(itsTextInfo != NULL);
	assert(index <= itsTextInfo->GetEntryCount());
	JString name = itsTextInfo->GetEntry(index).GetFullName();
	std::ifstream is(name);
	if (is.good())
		{
		JReadAll(is, text);
		if (name.EndsWith(kPlainType))
			{
			*format = kPlain;
			}
		else if (name.EndsWith(kHTMLType))
			{
			*format = kHTML;
			}
		JIndex findex;
		JBoolean ok = name.LocateLastSubstring(".", &findex);
		assert(ok);
		name.RemoveSubstring(findex, name.GetLength());
		ok = name.LocateLastSubstring(".", &findex);
		if (findex < name.GetLength())
			{
			*charset = name.GetSubstring(findex + 1, name.GetLength());
			}
		}
	else
		{
		itsIsSuccessful = kJFalse;
		}

	return itsIsSuccessful;
}
Exemplo n.º 4
0
JString
CBCClass::RemoveNamespace
	(
	const JCharacter* fullName
	)
{
	JString name = fullName;

	JIndex colonIndex;
	if (name.LocateLastSubstring("::", &colonIndex))
		{
		name.RemoveSubstring(1, colonIndex+1);
		}

	return name;
}
Exemplo n.º 5
0
JBoolean
CBHTMLStyler::GetXMLStyle
	(
	const JString&	tagName,
	JFontStyle*		style
	)
{
	JIndex i;
	if (!tagName.LocateLastSubstring(":", &i))
		{
		return kJFalse;
		}

	// tag name takes priority over XML namespaces

	JString s;
	if (i < tagName.GetLength())
		{
		s = tagName.GetSubstring(i+1, tagName.GetLength());
		if (GetWordStyle(s, style))
			{
			itsLatestTagName = s;
			return kJTrue;
			}
		}

	do
		{
		s = tagName.GetSubstring(1, i);
		if (GetWordStyle(s, style))
			{
			itsLatestTagName = s;
			return kJTrue;
			}

		i--;	// skip past the one we found
		}
		while (itsLatestTagName.LocatePrevSubstring(":", &i));

	return kJFalse;
}
void
GMMIMEParser::ParseContentType
	(
	const JString&	val,
	GMIMEHeader*	header
	)
{
	// we first need to determine the type. this will be found before the
	// first '/' which will be followed by the subtype.
	JString tVal	= val;
	tVal.TrimWhitespace();
	JSize length	= tVal.GetLength();

	JString type;
	JIndex findex;
	if (tVal.LocateSubstring("/", &findex) && (findex > 1))
		{
		type = tVal.GetSubstring(1, findex - 1);
		tVal.RemoveSubstring(1, findex);
		tVal.TrimWhitespace();
		type.ToLower();
		header->SetType(type);
		}
	else
		{
		return;
		}

	// now we need to determine the subtype
	JString subType;
	length			= tVal.GetLength();
	JBoolean found	= kJFalse;
	JIndex index;
	if (tVal.LocateSubstring(";", &index))
		{
		subType = tVal.GetSubstring(1, index - 1);
		tVal.RemoveSubstring(1, index);
		}
	else
		{
		subType = tVal;
		tVal.Clear();
		}

	tVal.TrimWhitespace();
	subType.TrimWhitespace();
	subType.ToLower();
	header->SetSubType(subType);

	if (tVal.IsEmpty())
		{
		return;
		}

	JPtrArray<JString> strings(JPtrArrayT::kDeleteAll);
	ParseContentParameters(tVal, &strings);
	JSize count = strings.GetElementCount();
	for (JIndex i = 1; i <= count; i += 2)
		{
		JString* str	= strings.NthElement(i);
		if (type == kTextType)
			{
			if (*str == "charset")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					header->SetCharSet(*str);
					}
				}
			}
		else if (type == kMultipartType)
			{
			if (*str == "boundary")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					header->SetBoundary(*str);
					}
				}
			}
		if ((type == kAppType) ||
			(type == kImageType) ||
			(type == kTextType))
			{
			if (*str == "name")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					if (str->LocateLastSubstring("/", &findex))
						{
						str->RemoveSubstring(1, findex);
						}
					if (str->LocateLastSubstring("\\", &findex))
						{
						str->RemoveSubstring(1, findex);
						}
					header->SetFileName(*str);
					}
				}
			}
		}
}