Esempio n. 1
0
string getDataRepresentation(const void *data, uInt dtaLenght, const uint8_t *cmmTag, const uInt &cmmLength, const DataRepresentation dtaRep, uInt stringSize)
{
    uInt cmmPosition = getCommandPosition(data, dtaLenght, cmmTag, cmmLength);

    if (cmmPosition != 0)
    {
        const uint8_t *castData = reinterpret_cast<const uint8_t *>(data);
        
        int sizeOffset = 0;
        if (stringSize <= 0)
        {
            stringSize = castData[cmmPosition + cmmLength];
            sizeOffset = 1;
        }
        
        switch (dtaRep)
        {
            //Translates the binary information into an ASCII reaable string
            case STRING_REPRESENTATION:
            {
                
                string aStr(reinterpret_cast<const char*>(&(castData[cmmPosition + cmmLength + sizeOffset])), stringSize);
                return aStr;
                break;
            }
            //Translates the binary information into a decimal (0-9) reaable string
            case DECIMAL_REPRESENTATION:
            {
                std::stringstream ss;
                for (int k = 0; k < stringSize; k++)
                {
                    ss << std::hex << setfill('0') << setw(2) <<  static_cast<unsigned int>( castData[cmmPosition + cmmLength + sizeOffset + k]);
                }
                return ss.str();
                break;
            }
            case HEX_REPRESENTATION:
            {
                
                string aStr(reinterpret_cast<const char*>((int)&(castData[cmmPosition + cmmLength + sizeOffset])), stringSize);
                return aStr;
                break;
            }   
            default:
                break;
        }
    }
    
    return "\0";
}
float
EDFBFont::StringWidth(const char *string, float size, float spacing, float shear, bool bold, eint32 length) const
{
	if(fEngine == NULL) return 0;
	if((int)size <= 0 || string == NULL || *string == 0 || length == 0 || !IsAttached()) return 0;

	EAutolock <EDFBGraphicsEngine> autolock(fEngine);
	if(autolock.IsLocked() == false || fEngine->InitCheck() != E_OK) return 0;

	int height = 0;
	fDFBFont->GetHeight(fDFBFont, &height);

	if(size != (float)height) return 0;

	float width = 0;
	if(length < 0 || (size_t)length > strlen(string)) length = (eint32)strlen(string);
	float delta = (float)ceil((double)(spacing * size));

	euint8 bytes = 0;
	const char *str = e_utf8_at(string, 0, &bytes);
	const char *tmp = str;
	while(!(tmp == NULL || bytes == 0 || (size_t)(tmp - string) > (size_t)length - (size_t)bytes))
	{
		EString aStr(tmp, (eint32)bytes);

		int bWidth = -1;
		fDFBFont->GetStringWidth(fDFBFont, aStr.String(), aStr.Length(), &bWidth);

		width += (float)(bWidth > 0 ? bWidth : height) + (tmp == str ? 0.f : delta);
		tmp = e_utf8_next(tmp, &bytes);
	}

	return width;
}
Esempio n. 3
0
static bool
AttrEquals(Implementor* aElement, nsIAtom* aNS, nsIAtom* aName, nsIAtom* aStr_,
           bool aIgnoreCase)
{
  FakeRef<nsIAtom> aStr(aStr_);
  auto match = [aStr, aIgnoreCase](const nsAttrValue* aValue) {
    return aValue->Equals(aStr, aIgnoreCase ? eIgnoreCase : eCaseMatters);
  };
  return DoMatch(aElement, aNS, aName, match);
}
void VJSONArrayWriter::AddString(const char *inCStr, JSONOption inModifier)
{
	if(testAssert(inCStr != NULL))
	{
		_ReopenIfNeeded();

		VString		aStr(inCStr);
		Add(aStr, inModifier);
	}
}
Esempio n. 5
0
static bool
AttrHasSuffix(Implementor* aElement, nsIAtom* aNS, nsIAtom* aName,
              nsIAtom* aStr_)
{
  FakeRef<nsIAtom> aStr(aStr_);
  auto match = [aStr](const nsAttrValue* aValue) {
    nsAutoString str;
    aValue->ToString(str);
    return StringEndsWith(str, nsDependentAtomString(aStr));
  };
  return DoMatch(aElement, aNS, aName, match);
}
Esempio n. 6
0
static bool
AttrIncludes(Implementor* aElement, nsIAtom* aNS, nsIAtom* aName,
             nsIAtom* aStr_)
{
  FakeRef<nsIAtom> aStr(aStr_);
  auto match = [aStr](const nsAttrValue* aValue) {
    nsAutoString str;
    aValue->ToString(str);
    const nsDefaultStringComparator c;
    return nsStyleUtil::ValueIncludes(str, nsDependentAtomString(aStr), c);
  };
  return DoMatch(aElement, aNS, aName, match);
}
void
ETextEditable::HideTyping(euint8 flag)
{
	if((flag != 0x00 && flag < 0x20) || flag > 0x7e) flag = 0x01;

	if(fTypingHidden != flag)
	{
		fTypingHidden = flag;

		EString aStr(fText);
		ETextEditable::SetText(aStr.String());

		Invalidate();
	}
}
ERect
EDFBFont::RenderString(EHandler *_view, const char *string, float size, float spacing, float shear, bool bold, eint32 length)
{
	if(fEngine == NULL || (int)size <= 0 || string == NULL || *string == 0 || length == 0) return ERect();

	EView *view = e_cast_as(_view, EView);
	if(view == NULL || view->Window() == NULL || view->IsPrinting()) return ERect();

	ERegion viewClipping;
	view->GetClippingRegion(&viewClipping);
	if(viewClipping.CountRects() <= 0) return ERect();

	EAutolock <EDFBGraphicsEngine> autolock(fEngine);
	if(autolock.IsLocked() == false || fEngine->InitCheck() != E_OK) return ERect();

	EDFBGraphicsDrawable *pix = e_cast_as(EGraphicsEngine::GetPixmap(view->Window()), EDFBGraphicsDrawable);
	EGraphicsContext *dc = EGraphicsEngine::GetContext(view);
	if(pix == NULL || pix->dfbSurface == NULL || dc == NULL) return ERect();

	if(!IsAttached()) return ERect();

	int height = 0, ascent = 0, descent = 0;
	fDFBFont->GetHeight(fDFBFont, &height);
	fDFBFont->GetAscender(fDFBFont, &ascent);
	fDFBFont->GetDescender(fDFBFont, &descent);

	if(size != (float)height) return ERect();

	float width = 0;
	if(length < 0 || (size_t)length > strlen(string)) length = (eint32)strlen(string);
	float delta = (float)ceil((double)(spacing * size));

	EPoint pt = view->ConvertToWindow(view->PenLocation());
	pt.y -= (float)(ascent + 1);

	e_rgb_color c = dc->HighColor();
	pix->dfbSurface->SetColor(pix->dfbSurface, c.red, c.green, c.blue, 255);
	pix->dfbSurface->SetDrawingFlags(pix->dfbSurface, DSDRAW_NOFX);
	pix->dfbSurface->SetFont(pix->dfbSurface, fDFBFont);

	euint8 bytes = 0;
	const char *str = e_utf8_at(string, 0, &bytes);
	const char *tmp = str;
	while(!(tmp == NULL || bytes == 0 || (size_t)(tmp - string) > (size_t)length - (size_t)bytes))
	{
		EString aStr(tmp, (eint32)bytes);

		int bWidth = -1;
		fDFBFont->GetStringWidth(fDFBFont, aStr.String(), aStr.Length(), &bWidth);

		for(eint32 i = 0; i < dc->Clipping()->CountRects(); i++)
		{
			ERect rect = dc->Clipping()->RectAt(i).FloorCopy();

			DFBRegion clipping;
			clipping.x1 = (int)rect.left;
			clipping.y1 = (int)rect.top;
			clipping.x2 = (int)rect.right;
			clipping.y2 = (int)rect.bottom;

			pix->dfbSurface->SetClip(pix->dfbSurface, &clipping);

			if(bWidth > 0)
				pix->dfbSurface->DrawString(pix->dfbSurface, aStr.String(), aStr.Length(),
							    (int)pt.x, (int)pt.y, (DFBSurfaceTextFlags)(DSTF_LEFT | DSTF_TOP));
//			else
//				pix->dfbSurface->FillRectangle(pix->dfbSurface, (int)pt.x + 3, (int)pt.y + 3, height - 6, height - 6);
		}

		pt.x += (float)(bWidth > 0 ? bWidth : height) + delta;
		width += (float)(bWidth > 0 ? bWidth : height) + (tmp == str ? 0.f : delta);

		tmp = e_utf8_next(tmp, &bytes);
	}

	pix->dfbSurface->SetFont(pix->dfbSurface, NULL);

	ERect updateRect;
	updateRect.left = pt.x;
	updateRect.right = pt.x + width;
	updateRect.top = pt.y;
	updateRect.bottom = updateRect.top + (float)height;
	view->ConvertFromWindow(&updateRect);
	updateRect &= viewClipping.Frame();

	return updateRect;
}
Esempio n. 9
0
void
ut_string(void)
{
//  useclass(Array, String);
  useclass(Lesser,Equal,Greater);
  useclass(AutoRelease);
  
  OBJ buf[] = { aStr("toto","tutu","","titi") };
  OBJ srt[] = { aStr("","titi","toto","tutu") };
  OBJ arr;

  OBJ pool = gnew(AutoRelease);

  UTEST_START("String")

    UTEST(gisEqual(aStr(""),aStr("")) == True);
    UTEST(gisEqual(aStr(""),aStr("titi")) == False);
    UTEST(gisEqual(aStr("titi"),aStr("")) == False);

    UTEST(gisEqual(aStr("titi"),aStr("titi")) == True);
    UTEST(gisEqual(aStr("tutu"),aStr("titi")) == False);

    UTEST(gcompare(aStr(""),aStr("")) == Equal);
    UTEST(gcompare(aStr(""),aStr("titi")) == Lesser);
    UTEST(gcompare(aStr("titi"),aStr("")) == Greater);

    UTEST(gcompare(aStr("tata"),aStr("titi")) == Lesser);
    UTEST(gcompare(aStr("titi"),aStr("titi")) == Equal);
    UTEST(gcompare(aStr("tutu"),aStr("titi")) == Greater);

    UTEST(gcompare(aStr("titis"),aStr("tutu")) == Lesser);
    UTEST(gcompare(aStr("tutu"),aStr("titis")) == Greater);
    UTEST(gcompare(aStr("titis"),aStr("titi")) == Greater);
    UTEST(gcompare(aStr("titi"),aStr("titis")) == Lesser);

    arr = aArrayRef(buf, COS_ARRLEN(buf));

    UTEST(gfind(arr, aStr("toto")) != Nil);
    UTEST(gfind(arr, aStr("tutu")) != Nil);
    UTEST(gfind(arr, aStr("titi")) != Nil);
    UTEST(gfind(arr, aStr("tata")) == Nil);
    UTEST(gfind(arr, aStr("titis")) == Nil);
    UTEST(gfind(arr, aStr("totos")) == Nil);
    UTEST(gfind(arr, aStr("tutus")) == Nil);
    UTEST(gfind(arr, aStr("")) != Nil);
    
    UTEST(gfind(arr, aFun(gisEqual, aStr("titi"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("toto"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("tutu"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("titis"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("totos"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("tutus"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr(""), __1)) != Nil);

    gsort(arr, aFun(gcompare,__1,__2));

    UTEST(gisEqual(arr, aArrayRef(srt, COS_ARRLEN(srt))) == True);

    UTEST(gfind(arr, aFun(gcompare, aStr("titi"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("toto"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("tutu"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("titis"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("totos"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("tutus"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr(""), __1)) != Nil);

    arr = aArrayRef(0, 0);

    UTEST(gfind(arr, aStr("tata")) == Nil);
    UTEST(gfind(arr, aStr("")) == Nil);

    UTEST(gfind(arr, aFun(gisEqual, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr(""), __1)) == Nil);

    UTEST(gfind(arr, aFun(gcompare, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr(""), __1)) == Nil);

  UTEST_END

  grelease(pool);
}
void
nsAbAutoCompleteSession::AddToResult(const PRUnichar* pNickNameStr,
                                     const PRUnichar* pDisplayNameStr,
                                     const PRUnichar* pFirstNameStr,
                                     const PRUnichar* pLastNameStr,
                                     const PRUnichar* pEmailStr,
                                     const PRUnichar* pNotesStr,
                                     const PRUnichar* pDirName,
                                     PRUint32 aPopularityIndex,
                                     PRBool bIsMailList, PRBool pDefaultMatch,
                                     nsIAutoCompleteResults* results)
{
    nsresult rv;
    PRUnichar* fullAddrStr = nsnull;

    if (pDefaultMatch)
    {
        if (mDefaultDomain[0] == 0)
            return;

        nsAutoString aStr(pDisplayNameStr);
        if (aStr.FindChar('@') == kNotFound)
        {
            aStr.Append(PRUnichar('@'));
            aStr += mDefaultDomain;
        }
        fullAddrStr = ToNewUnicode(aStr);
    }
    else
    {
        if (mParser)
        {
            nsXPIDLCString fullAddress;
            nsXPIDLCString utf8Email;
            if (bIsMailList)
            {
                if (pNotesStr && pNotesStr[0] != 0)
                    utf8Email.Adopt(ToNewUTF8String(nsDependentString(pNotesStr)));
                else
                    utf8Email.Adopt(ToNewUTF8String(nsDependentString(pDisplayNameStr)));
            }
            else
                utf8Email.Adopt(ToNewUTF8String(nsDependentString(pEmailStr)));

            mParser->MakeFullAddress(nsnull, NS_ConvertUCS2toUTF8(pDisplayNameStr).get(),
                                     utf8Email, getter_Copies(fullAddress));
            if (!fullAddress.IsEmpty())
            {
                /* We need to convert back the result from UTF-8 to Unicode */
                fullAddrStr = nsCRT::strdup(NS_ConvertUTF8toUCS2(fullAddress.get()).get());
            }
        }

        if (!fullAddrStr)
        {
            //oops, parser problem! I will try to do my best...
            const PRUnichar * pStr = nsnull;
            if (bIsMailList)
            {
                if (pNotesStr && pNotesStr[0] != 0)
                    pStr = pNotesStr;
                else
                    pStr = pDisplayNameStr;
            }
            else
                pStr = pEmailStr;
            // check this so we do not get a bogus entry "someName <>"
            if (pStr && pStr[0] != 0) {
                nsAutoString aStr(pDisplayNameStr);
                aStr.AppendLiteral(" <");
                aStr += pStr;
                aStr.AppendLiteral(">");
                fullAddrStr = ToNewUnicode(aStr);
            }
            else
                fullAddrStr = nsnull;
        }
    }

    if (fullAddrStr && ! ItsADuplicate(fullAddrStr, aPopularityIndex, results))
    {
        nsCOMPtr<nsIAutoCompleteItem> newItem = do_CreateInstance(NS_AUTOCOMPLETEITEM_CONTRACTID, &rv);
        if (NS_SUCCEEDED(rv))
        {
            nsAbAutoCompleteParam *param = new nsAbAutoCompleteParam(pNickNameStr, pDisplayNameStr, pFirstNameStr, pLastNameStr, pEmailStr, pNotesStr, pDirName, aPopularityIndex, bIsMailList);
            NS_IF_ADDREF(param);
            newItem->SetParam(param);
            NS_IF_RELEASE(param);

            // how to process the comment column, if at all.  this value
            // comes from "mail.autoComplete.commentColumn", or, if that
            // doesn't exist, defaults to 0
            //
            // 0 = none
            // 1 = name of addressbook this card came from
            // 2 = other per-addressbook format (currrently unused here)
            //
            if (mAutoCompleteCommentColumn == 1) {
                rv = newItem->SetComment(pDirName);
                if (NS_FAILED(rv)) {
                    NS_WARNING("nsAbAutoCompleteSession::AddToResult():"
                               " newItem->SetComment() failed\n");
                }
            }

            // if this isn't a default match, set the class name so we can style
            // this cell with the local addressbook icon (or whatever)
            //
            rv = newItem->SetClassName(pDefaultMatch ? "default-match" :
                                       "local-abook");
            if (NS_FAILED(rv)) {
                NS_WARNING("nsAbAutoCompleteSession::AddToResult():"
                           " newItem->SetClassName() failed\n");
            }

            newItem->SetValue(nsDependentString(fullAddrStr));
            nsCOMPtr<nsISupportsArray> array;
            rv = results->GetItems(getter_AddRefs(array));
            if (NS_SUCCEEDED(rv))
            {
                PRUint32 nbrOfItems;
                rv = array->Count(&nbrOfItems);

                PRInt32 insertPosition = 0;

                for (; insertPosition < nbrOfItems && !pDefaultMatch; insertPosition++)
                {
                    nsCOMPtr<nsISupports> currentItemParams;
                    nsCOMPtr<nsIAutoCompleteItem> resultItem;
                    nsresult rv = array->QueryElementAt(insertPosition, NS_GET_IID(nsIAutoCompleteItem),
                                                        getter_AddRefs(resultItem));
                    if (NS_FAILED(rv))
                        continue;
                    rv = resultItem->GetParam(getter_AddRefs(currentItemParams));
                    if (NS_FAILED(rv))
                        continue;

                    param = (nsAbAutoCompleteParam *)(void *)currentItemParams;
                    if (aPopularityIndex > param->mPopularityIndex) // sort the search results by popularity index
                        break;
                }

                rv = array->InsertElementAt(newItem, insertPosition);
            }
        }
    }
    PR_Free(fullAddrStr);
}